Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
Preprocessor directives in C and C++ - what they mean

The C pre-processor runs on your C and C++ code at compile time prior to the main compile process. Source lines starting with the # character are processed to roduce a new source code file (internally - you don't normally see this) which is then the input to the compile process "proper".

Preprocessor DIRECTIVES include:

#include
To include the contents of another file at this point. If the other file is embedded in chevrons (< to >), the included file is a standard system one from system libraries, but if it's embedded in double quotes, it's your own include file from your own folder / directory. Include files often have an extension .h for header, but this doesn't matter to C / C++ - it's just a label

#define
Define a variable within the pre-preocessor. Subseqent refefences to that named variable will be substituted for the value given at compile time, allowing you to fix data at a specific build - such things as array sizes. It's convention to write preprocessor variable name all in CAPITALS to help the maintenance programmer, but it's not a vital rule.

Preprocessor variables can also be set on the compile time command line; in cc and gcc and g++, that's done with the -D switch.

#ifdef
#ifndef
Allow you to check whether a variable has been defined - very useful to see ig your file has been brought in by another file at compile time, or is being compiled on its own. Also useful for conditional code based on compile time selection, and to avoid code being loaded twice where there's a comple #include structure. "ifdef" is "if defined" and "ifndef" is "if NOT defined".

#endif
Signifies the end of a block started by "ifdef" or "ifndef".

Note that directives do NOT end with a semicolon character - they are a different language to C and C++, and they end at the end of the line.

Example - [here].
(written 2015-10-27)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C201 - C and C based languages - C Language Fundamentals
  [4566] C - why is slow to write and debug) but fast to run? - (2015-11-01)
  [4324] Learning to program - variables and constants - (2014-11-22)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [3591] Integer types, and integer overflows, in C - (2012-01-25)
  [3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
  [3234] Your program - you just provide the filling in the sandwich - (2011-04-08)
  [3120] Learning to write good programs in C and C++ - separating out repeated code - (2011-01-04)
  [2842] Staring a C course with Hello World - why? - (2010-06-30)
  [2576] What does const mean? C and C++ - (2010-01-15)
  [2005] Variables and pointers and references - C and C++ - (2009-01-23)
  [1671] Compiling C programs with gcc - an overview - (2008-06-10)
  [888] Turning C from source to a running program - (2006-10-06)

C204 - C and C based languages - Functions, Macros and programs in multiple files
  [4557] Function prototype - what they are and why you should use them - C and C++ - (2015-10-27)
  [4554] Passing information into functions in C - by name, by value - (2015-10-26)
  [4338] Passing arrays into functions in C - (2014-12-02)
  [3721] Naming blocks of code, structures and Object Orientation - efficient coding in manageable chunks - (2012-05-06)
  [3717] Returning extra results from a function in C - (2012-05-03)
  [3237] Using functions to keep look and feel apart from calculations - simple C example - (2011-04-09)
  [2841] C Course exercise and sample answer - source in 2 files - (2010-06-30)
  [2575] Sharing variables between files of code in C - extern - (2010-01-14)
  [2570] Function Prototypes in C - (2010-01-11)
  [1478] Some new C programming examples - files, structs, unions etc - (2007-12-19)
  [1163] A better alternative to cutting and pasting code - (2007-04-26)
  [775] Do not duplicate your code - (2006-06-23)

C230 - C and C based languages - Revision of C
  [4466] Moving from C to C++ - Structured to Object Oriented - a lesson for engineers - (2015-03-28)


Back to
Passing information into functions in C - by name, by value
Previous and next
or
Horse's mouth home
Forward to
Strings in C - strncmp strncpy and friends
Some other Articles
When do I use the this keyword in C++?
Well House Consultants - Python courses / what's special.
Strings in C - strncmp strncpy and friends
Preprocessor directives in C and C++ - what they mean
RUby - loading, using, changing, storing JSON format data
Scenario outlines - tables of values to test - in Gherkin / Cucumber
Testing your new class - first steps with cucumber
Build up classes into applications sharing data types in Ruby
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4555_Pre ... -mean.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat