Re: #define




"Ivan" <idiprima@xxxxxxxxxxx> wrote in message

What is the scope of preprocessor #define?
Does it depends on the compiler?

File scope, in all conforming implementations. However #defines are frequently placed in headers which are #included by more than one dot c file.

Some compilers separate out the preprocessing step from compilation proper. Preprocessing manages the instructions that start with a hash. However this will be transparent to you unless you invoke the preprocessor only (typically the command is cpp or similar).

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


.



Relevant Pages

  • Re: Histogram of character frequencies
    ... It's completely acceptable to have variables defined at file scope in ... Global objects have many ... confirm that it works fine with both MicroSoft compiler and BorLand. ... But no "conforming implementation" on Windows rejects it! ...
    (comp.lang.c)
  • Re: Histogram of character frequencies
    ... Global objects have many ... This is an especially poor argument for justifying file scope objects. ... believe any C compiler anywhere would reject it. ... end of the world - the standard library is always linked in so the ...
    (comp.lang.c)
  • Re: Histogram of character frequencies
    ... It's completely acceptable to have variables defined at file scope in ... Global objects have many ... confirm that it works fine with both MicroSoft compiler and BorLand. ... way that you're using it is incorrect, ...
    (comp.lang.c)
  • Re: 2D array of structures
    ... foo.c:30: warning: initialization discards qualifiers from pointer target ... I fixed this by shifting the declaration to file scope. ... Types at file scope, objects at function scope. ... compiler diagnostic settings, ...
    (comp.lang.c)
  • Re: register caching of static variables
    ... >static int a; ... >in a register that is not the case. ... Here the variable "a" has file scope and internal linkage. ... C compiler would be allowed to rewrite the code as: ...
    (comp.lang.c)