Editing The C Preprocessor and pound Defines

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 
Early draft, may not be useful to read
 
Early draft, may not be useful to read
Or:  The C Preprocssor and #Defines ( #Define seems to be illegal in the title of a page )
+
 
 
== Overview ==  
 
== Overview ==  
  
Line 29: Line 29:
 
== Calculations ==
 
== Calculations ==
  
The ability to do calculations with the preprocessor is a bit odd, as shown above most of the #define work simply does text substution, with the effect of calculation comming in the compiler optimization.  There is an odd way of doing calculations, the #if directive will evalue what follows it interperting the symbols as long integers, and treating 0 as false and anything else as true.  You can do the calculation, and even compare the result with ==, but there does not seem to be any direct way of saving the result.  Here is an example:
 
 
 
Look at the links below for more information about #if and related directives.
 
 
 
== Messages in the Output ==
 
 
    #warning yyyy
 
 
sends warning yyyy to the output and continues the compilation process ( actually in the preprocessor )
 
 
    #error xxxxxx
 
 
sends error xxxxxx to the output and ends compilation process
 
  
 
== How C Compiles ==
 
== How C Compiles ==
Line 64: Line 49:
  
  
External links to preprocessor information:
 
  
  
* [http://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_3.html#SEC33  3. Macros]
 
  
* [http://gcc.gnu.org/onlinedocs/cpp/ The C Preprocessor]
 
  
* [http://publications.gbdirect.co.uk/c_book/chapter7/directives.html 7.3. Directives]
+
External links to preprocessor information:
 
 
* [http://www.gamedev.net/reference/articles/article1798.asp Organizing Code Files in C and C++] Not just the preprocessor but more general information on the structure of projects.
 
 
 
 
 
[[Category:PIC]][[Category:BoostC]]
 

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)