Thanks, I had indeed misunderstood Ken's point.

However, if I change the code thus:
-----------------------------------
void func(void)
{
  volatile int timeout;

  return;

  timeout = 0xFFFF;
  while (timeout--);
}
-----------------------------------
the only difference is that the warning is printed twice, rather than 3
times. :)

Any other ideas?

Mary-Ann


Maarten Brock wrote:
> Mary-Ann,
> 
> I think you missed the point Ken Jackson was trying to make.
> Even if you do NOT insert the return-statement the code can
> still be optimized out by the compiler because it has no
> so-called side-effects. Only if you make the timeout variable
> 'volatile' you disallow the compiler to make any assumptions
> about its use and thus the generated code must actually do all the
> loops you intended. 
> 
> Greets,
> Maarten
> 
>> Yes, I want the compiler to optimise it away, but I'd like it to do
>> so without complaining about the "timeout" variable.  The following
>> code has similar problems: 
>> 
>> void func(void)
>> {
>>   return;
>> 
>>   {
>>     int timeout;
>>     timeout = 0xFFFF;
>>     while (timeout--);
>>   }
>> }
>> 
>> Mary-Ann
>> 
>> 
>> Ken Jackson wrote:
>>> I don't know the answer, though I offer an observation.
>>> 
>>> Most compilers will optimize away the delay that you are trying to
>>> implement.  Therefore you should declare timeout this way:
>>> 
>>>   volatile int timeout;
>>> 
>>> Also, when I do it that way, I don't get the warning.
>>> 
>>> -Ken Jackson
>>> 
>>> Mary-Ann Johnson writes:
>>>> If I compile the following code (SDCC 2.7.0):
>>>> 
>>>> ------------------------------------------------
>>>> void func(void)
>>>> {
>>>>   int timeout;
>>>> 
>>>>   return;
>>>> 
>>>>   timeout = 0xFFFF;
>>>>   while (timeout--);
>>>> }
>>>> ------------------------------------------------
>>>> 
>>>> SDCC produces the following warnings:
>>>> "src/test.c:8: warning 84: 'auto' variable 'timeout' may be used
>>>> before initialization src/test.c:8: warning 84: 'auto' variable
>>>> 'timeout' may be be used before initialization src/test.c:8:
>>>> warning 84: 'auto' variable 'timeout' may be used before
>>>> initialization"  
>>>> 
>>>> Any idea why?
>>>> 
>>>> And before someone says "Don't call 'return' there!" - this
>>>> scenario happens when a macro is set to "return" to eliminate the
>>>> 2nd half of a function. 
>>>> 
>>>> Thanks,
>>>> Mary-Ann

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to