Re: Is there any way to give a warning when a nested function use its parent function's local variable value.

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

 



So are there any plans to enforce my proposed policy in GCC, or the
upcoming C standard?

On Wed, Nov 26, 2014 at 4:56 AM, xinglp <xinglp@xxxxxxxxx> wrote:
>> I don't think you need a warning in this particular case, perhaps a
>> better way would be for the compiler to enforce a rule that forbids
>> access of function pointers of inner functions that referencing local
>> variables of its parent function.
> Yes, this is better. For now, when this happend, there's only a
> segfault and it's diffcult to dig out.
>>
>> For example, both:
>>
>> void *foo(int x)
>> {
>>     int a;
>>     void foo2(int i)
>>     {
>>         // I want warning for the below code.
>>         if (i == a){}
>>         x += i;
>>         a += i;
>>     }
>>     foo2(a);
>>
>>     return foo2;
>> }
>>
>> and:
>>
>> void *bar;
>>
>> void foo(int x)
>> {
>>     int a;
>>     void foo2(int i)
>>     {
>>         // I want warning for the below code.
>>         if (i == a){}
>>         x += i;
>>         a += i;
>>     }
>>     foo2(a);
>>
>>     bar = foo2;
>> }
>>
>>
>> should return an error.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux