|
From: Sylvester S. <syl...@gm...> - 2008-11-23 15:21:25
|
Thanks a lot! It worked! On Fri, Nov 21, 2008 at 9:50 AM, Sylvester <syl...@gm...>wrote: > Greg Chicares wrote: > > [Please don't top-post: > http://en.wikipedia.org/wiki/Posting_style#Top-posting > Thanks.] > > On 2008-11-21 02:40Z, Sylvester Steele wrote: > > > I am basically declaring an extern array in a file say global1.h. The I am > using it in 2-3 other files. I include this file. > > I declare it like this: > > extern int outputs[4]; > > > This declaration enables you to access and use the variable, > as long as it's defined elsewhere. I'd generally omit the > dimension '4' here: then you don't have to change it in the > header when you change it in the definition. > > > > to use this extern array I do: > > int outputs[4]; - this outside of any function, in file that I want to > access the extern variable. > > > That's a definition. You need exactly one definition, in > exactly one file. The 'extern' declaration enables the > variable defined here to be accessed elsewhere. > > > > If I do this in 1 file only (ie declaration an 1 file and use in 1 more > different file) the program compiles. > > However if I use it more than one file (declaration an 1 file and use in 2 > or more different files) it does not compile. > > > One declaration is sufficient for you to use the variable in > any file that includes the header containing the declaration. > You don't have to repeat the definition: in fact, it's an error. > A definition allocates space. You want to allocate space only > once for a variable. > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the worldhttp://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > MinGW-users mailing lis...@li... > > You may change your MinGW Account Options or unsubscribe at:https://lists.sourceforge.net/lists/listinfo/mingw-users > > This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists. We ask that you be polite and do the same. > > > > Thanks a lot. I'll try this. > |