[CSC 315] Ifdef
Andrew J. Pounds
pounds_aj at mercer.edu
Thu Oct 30 17:51:12 EDT 2014
We are using it for several things -- you can do the mechanism inside
the makefile to "turn on" and turn off portions of your code at compile
time. That is what we were talking about last week. The thing I was
showing you at the end of class today was different -- that was called
"ifdef wrapping" a function so that there is only once instance of a
method defined at link time. This has to be done when you use segmented
makefiles.
Think about it, if you have a segmented (and subsequently lots of files
to "make"), each of this will probably have a list of files to include.
C/C++ doesn't want to see things defined multiple times, so we do the
|#ifndef BOX_H
#define BOX_H
my c++ class definition
#endif
|
I may have multiple files that include the one above -- and that have to
include it to even compile -- but when it comes time to link all of the
object files together, only one instance is needed. The things above
and below the code are used by the linker in this scenario -- if there
not a BOX_H defined, the define above will define the BOX_H symbol (and
the code will be compiled and placed in the object space). When this
code is encoutered in another include file, the BOX_H symbol will
already be defined and the code will not be compiled (which would cause
a compile error because all of the varialbles and stuff have already
been defined).
The pre-processor is very powerful.
On 10/30/2014 05:34 PM, Kevin L. Long wrote:
>
> I should have phrased that better. I meant what are we using it for?
> It says we're using it to choose between program 1 and 2, but I got
> the impression in class (maybe I misunderstood) that we just used the
> terminal for that.
>
> ------------------------------------------------------------------------
> *From:* Andrew J. Pounds <pounds_aj at mercer.edu>
> *Sent:* Thursday, October 30, 2014 5:07 PM
> *To:* Kevin L. Long
> *Subject:* Re: Ifdef
> On 10/30/2014 04:51 PM, Kevin L. Long wrote:
>>
>> Exactly in what manner is ifdef supposed to be used?
>>
>
> http://www.cplusplus.com/doc/tutorial/preprocessor/
> --
> Andrew J. Pounds, Ph.D. (pounds_aj at mercer.edu)
> Professor of Chemistry and Computer Science
> Mercer University, Macon, GA 31207 (478) 301-5627
> http://faculty.mercer.edu/pounds_aj
--
Andrew J. Pounds, Ph.D. (pounds_aj at mercer.edu)
Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
http://faculty.mercer.edu/pounds_aj
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://theochem.mercer.edu/pipermail/csc315/attachments/20141030/542307d7/attachment.html>
More information about the csc315
mailing list