• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Stupid "warning: declaration of 'index' shadows a global declaration"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Re: Stupid "warning: declaration of 'index' shadows a global declaration" (From: Steve Mills <email@hidden>)
 >Re: Stupid "warning: declaration of 'index' shadows a global declaration" (From: Clark Cox <email@hidden>)
 >Re: Stupid "warning: declaration of 'index' shadows a global declaration" (From: Keary Suska <email@hidden>)

  • Prev by Date: Re: Xcode not responding when running unit tests
  • Next by Date: Re: Stupid "warning: declaration of 'index' shadows a global declaration"
  • Previous by thread: Re: Stupid "warning: declaration of 'index' shadows a global declaration"
  • Next by thread: Re: Stupid "warning: declaration of 'index' shadows a global declaration"
  • Index(es):
    • Date
    • Thread