avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] [bug #39875] Warning 1 unused variable '__ticks' [-Wunuse


From: anonymous
Subject: [avr-libc-dev] [bug #39875] Warning 1 unused variable '__ticks' [-Wunused-variable] C:\PROGRA~2\Atmel\ATMELT~1\AVR8GC~1\Native\342~1.939\AVR8-G~1\av
Date: Tue, 27 Aug 2013 06:01:44 +0000
User-agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0

URL:
  <http://savannah.nongnu.org/bugs/?39875>

                 Summary: Warning       1       unused variable '__ticks'
[-Wunused-variable]     
C:\PROGRA~2\Atmel\ATMELT~1\AVR8GC~1\Native\342~1.939\AVR8-G~1\av
                 Project: AVR C Runtime Library
            Submitted by: None
            Submitted on: Tue 27 Aug 2013 06:01:43 AM UTC
                Category: Library
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: libc code
                  Status: None
        Percent Complete: 0%
             Assigned to: None
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 1.8.0
           Fixed Release: None

    _______________________________________________________

Details:

_delay_ms has the following definition:

void
_delay_ms(double __ms)
{
        uint16_t __ticks;
        double __tmp ; 
#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
  !defined(__DELAY_BACKWARD_COMPATIBLE__) &&       \
  __STDC_HOSTED__
        uint32_t __ticks_dc;
        extern void __builtin_avr_delay_cycles(unsigned long);
        __tmp = ((F_CPU) / 1e3) * __ms;

        #if defined(__DELAY_ROUND_DOWN__)
                __ticks_dc = (uint32_t)fabs(__tmp);

        #elif defined(__DELAY_ROUND_CLOSEST__)
                __ticks_dc = (uint32_t)(fabs(__tmp)+0.5);

        #else
                //round up by default
                __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
        #endif

        __builtin_avr_delay_cycles(__ticks_dc);

#else
        __tmp = ((F_CPU) / 4e3) * __ms;
        if (__tmp < 1.0)
                __ticks = 1;
        else if (__tmp > 65535)
        {
                //      __ticks = requested delay in 1/10 ms
                __ticks = (uint16_t) (__ms * 10.0);
                while(__ticks)
                {
                        // wait 1/10 ms
                        _delay_loop_2(((F_CPU) / 4e3) / 10);
                        __ticks --;
                }
                return;
        }
        else
                __ticks = (uint16_t)__tmp;
        _delay_loop_2(__ticks);
#endif
}

If it is possible for the first half of the conditional to be true (it was for
me) then the definitions of _delay_ms and _delay_us are obviously incorrect. 
(__ticks is not referenced before the #else clause.)  I suggest moving the
declaration of __ticks to the #else clause, as follows: 

void
_delay_ms(double __ms)
{
        double __tmp ; 
#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__) && \
  !defined(__DELAY_BACKWARD_COMPATIBLE__) &&       \
  __STDC_HOSTED__
        uint32_t __ticks_dc;
        extern void __builtin_avr_delay_cycles(unsigned long);
        __tmp = ((F_CPU) / 1e3) * __ms;

        #if defined(__DELAY_ROUND_DOWN__)
                __ticks_dc = (uint32_t)fabs(__tmp);

        #elif defined(__DELAY_ROUND_CLOSEST__)
                __ticks_dc = (uint32_t)(fabs(__tmp)+0.5);

        #else
                //round up by default
                __ticks_dc = (uint32_t)(ceil(fabs(__tmp)));
        #endif

        __builtin_avr_delay_cycles(__ticks_dc);

#else
        uint16_t __ticks;

        __tmp = ((F_CPU) / 4e3) * __ms;
        if (__tmp < 1.0)
                __ticks = 1;
        else if (__tmp > 65535)
        {
                //      __ticks = requested delay in 1/10 ms
                __ticks = (uint16_t) (__ms * 10.0);
                while(__ticks)
                {
                        // wait 1/10 ms
                        _delay_loop_2(((F_CPU) / 4e3) / 10);
                        __ticks --;
                }
                return;
        }
        else
                __ticks = (uint16_t)__tmp;
        _delay_loop_2(__ticks);
#endif
}





    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?39875>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]