avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] life span of #define


From: Christian Vogel
Subject: Re: [avr-gcc-list] life span of #define
Date: Sat, 17 Aug 2002 11:29:07 +0200
User-agent: Mutt/1.2.5.1i

Hi Marlin,

> What is the life span of a #define or #include. Is it to the end of the C 
> file that defined or included it?

The preprocessor converts your input file with all #includes and #defines
into one big chunk of C-Code which is then read by the actual compiler. So
a #define is not only in effect in your source-file but in all files
that you include (and in turn are included by them...) afterwards.

> Is the #define or #include stuff flushed before the next C files is 
> analyzed?

Every C-file is (at least with gcc, other compilers might have some
magic pre-compiled headers/libraries/...) compiled independent of
every other file.

> Somewhere I read that it is bad programming style to include 
> include files from an include file. Is this TRUE?

No, it's perfectly OK to include files in every other file.
It may be a matter of taste and complexity of maintainance, though.

I would advise to read some good books on this topic first! ;-)

> Does someone know of a good source of info so I can get a grip on how the 
> preprocessor works? I want to understand how to intellegently use the 
> #define #ifdef #ifndef stuff, instead of tumbling around with it.

The gcc-documentation might be a good start, and every good C-Book should
explain the preprocessor!

   Chris

-- 
The problem with bad plans is, for each one created, there's an
idiot somewhere willing to carry it out -- Kirk Mitchell
avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]