View Single Post
  #5   Spotlight this post!  
Unread 18-01-2004, 02:07
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Re: Using the extern keyword.

Quote:
Originally Posted by SeanCassidy
Hmm, when the variable is changed in user_routines.c, do you have to extern it back in u_r_f.c? Like so:

Code:
/*user_routines_fast.c*/
int foo = 263;
extern user_routines_function();    /*Is this extern needed?*/
extern foo = foo - 1;               /*Do we need the extern now,
                                     *because it was modified in u_r.c?*/

/*user_routines.c*/
user_routines_function()
{
  extern foo = foo + 3;
}
extern should never be used inside an expression like that. It is only used in declarations made at the file-scope level. Thus, you just do stuff like this:

/*user_routines_fast.c*/
int foo;

void myfunc(){
foo=foo+1;
}

/*user_routines.c*/
extern int foo;

void myfunc2(){
foo=foo+3;
}


They keyword extern is NEVER needed with function prototypes, as they are extern implicitly.

-Rob
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php