Re: Split into several .c files -> where to put the global variables?

From: Ralf Fassel (ralfixx_at_gmx.de)
Date: 09/07/05


Date: Wed, 07 Sep 2005 11:34:02 +0200


* "Alexander Farber" <Alexander.Farber@gmail.com>
| Should I keep the variables in the main token-server.c and put the
| "extern" declarations into token-server.h?

That's the usual way this is done. You need the declaration in every
source file which uses the global variable, and the definition in
exactly one source file. You can play tricks with the preprocessor in
the header file, but in my experience it is cleaner if you maintain
the double list. If you get it wrong, the compiler will complain
anyway.

R'



Relevant Pages

  • Re: Syntax for union parameter
    ... of mpz_init is in some source file. ... and the header file that declares it ... pick up the function declarations that are exported (the ones without ... When you recompile a module, it updates the associated header file. ...
    (comp.lang.c)
  • Re: Syntax for union parameter
    ... I'm not sure if you're saying yes or no. ... of mpz_init is in some source file. ... pick up the function declarations that are exported (the ones without ... as happens when you have external libraries which are not ...
    (comp.lang.c)
  • Re: cout << char*
    ... "Igor Tandetnik" wrote: ... Each source file is ... Including CLib.h in library.cpp is adding the declarations to the definitions. ... int id ...
    (microsoft.public.vc.language)
  • Re: Newbie: structs in vectors
    ... How/where do I define a constructor function? ... He meant seperate your declarations from your definitions. ... you can define the constructor in it's source file Total.cpp with an ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Syntax for union parameter
    ... I'm not sure if you're saying yes or no. ... Within a single source file, a compiler could perform two passes over ... function declarations, write them to a temporary file, and then ...
    (comp.lang.c)