The main function usually call (invoke) other functions during the program execution.
#include <iostream.h> // Header file containing useful definitions... int main(int argc, char *argv[]) { cout << "Hello World\n"; } |
CC [options] ProgramFileName.C |
a.out |
Option | Meaning | Example | What does it do |
---|---|---|---|
-o FileName | Rename the executable output file | CC -o myProg myProg.C |
Compiler will rename executable output file from a.out to myProg |
-g | Debug Mode | CC -g myProg.C |
Compiler will insert additional information in output a.out that can be use with a debugger (a tool to help programmers find errors in the program) |
-c | Create relocatable object code | CC -c myProg.C |
Compiler will NOT produce a directly executable computer program, but
a program that can be combined with other "relocatable" codes
NOTE: use this option when your program consists of multiple text files |
-lLibFile | Specify an additional library file | CC myProg.C -lmath |
Tell the C++ compiler to "link in" (include) functions from the "math" function library. The actual UNIX filename for a C++ library file "math" is "libmath.a" |
CC -o myProg myProg.C | Compile myProg.C into the executable output file myProg (instead of a.out |
CC -g -c myProg.C | Produce relocatable object code with debug information |
CC -g -c myFile1.C // This command will produce the // relocatable object file myFile1.o // (which can be combined with other // relocatable object files CC -g -c myFile2.C // This command will produce another // relocatable object file myFile2.o // // We can now combine these files ! CC -o myProg myFile1.o myFile2.o |
Once you have tested your program thoroughly and made sure that it works, then recompile ALL the program files again, but WITHOUT the -g option:
CC -fast -c myFile1.C CC -fast -c myFile2.C CC -o myProg myFile1.o myFile2.o |
#define SYMBOL (Defines a symbol) #undef SYMBOL (Undefines a symbol) #include FILENAME (Insert file FILENAME in this spot) #if CONDITION (Skip to #endif if CONDITION is false) #ifdef SYMBOL (Skip to #endif if SYMBOL is NOT DEFINED) #ifndef SYMBOL (Skip to #endif if SYMBOL is DEFINED) #else (else part - used with #if...) #elif ("else if" - used with #if...) #endif (Used to mark the rang of #ifdef and #ifndef) |
#ifdef SYMBOL Text between (#ifdef, #endif) is removed if SYMBOL is not defined [#else ... else part ] #endif |
#if CONDITION Text between (#ifdef, #endif) is removed if SYMBOL is not defined [#else ... else part ] #endif |
=========== Program.C: =========== #include "params.h" int main(int argc, char *argv[]) { ... } |
=========== Program.C: =========== #include "params1.h" // params1.h includes params0.h #include "params2.h" // params2.h includes params0.h int main(int argc, char *argv[]) { ... } |
For example: params1.h may include params3.h
=========== Trick to prevent a parameter file to be process more than once =========== #ifndef _ThisParameterFileName_ #define _ThisParameterFileName_ .... put the parameter definitions here #endif |
The SECOND time that the parameter file is processed, the symbol _ThisParameterFileName_ HAS ALREADY BEEN defined.
As a result, the entire file (till #endif) is skipped...
Look inside "nested-include.i" to see the effect of the "ifdef"