Re: Stupid "warning: declaration of 'index' shadows a global declaration"
Re: Stupid "warning: declaration of 'index' shadows a global declaration"
- Subject: Re: Stupid "warning: declaration of 'index' shadows a global declaration"
- From: David Hayes <email@hidden>
- Date: Sun, 15 Nov 2009 15:44:06 -0500
On 2009-11-15, at 11:30 AM, Keary Suska wrote:
>
> I would add that what I think is "stupid" is the warning being flagged when a variable declaration masks a function declaration. If it were just variable shadowing I would heartily support it. Not only is the warning immediately misleading, but what coder in her right mind would make a function call without parentheses?
>
This is because the function name by itself is actually a pointer to the function. Example if you are loading a windows dll you typically load the library, declare a function pointer and pull the dll's exported function address into your pointer. You can then use your function pointer as a function call.
Also it could be used in drivers where you need a lot of speed. Rather than having to fall through a switch or if, then, else you could set up a table of function pointers and call a function by its index in the table. Fast but brutally unreadable and difficult to debug. You still might see it in an embedded systems application in a situation where speed trumps all.
eg.
int add2Integers( int i, int j )
{
return i + j;
}
int main()
{
// declare a function pointer with the appropriate protot-type
// and initialize it to the address of our function
int ( *myFunctionPointer ) ( int, int ) = add2Integers;
// Now we can use our function pointer
int k = myFunctionPointer( 1, 2 );
printf( "k = %d\n", k );
return 0;
} _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden