What are .ch files ?
ch means “C header” and as name implied, this coding way borrowed from C language.
Normally, that files written individually and are included into .prg file via #include directive.
In general, .ch files includes pre-processor directives for constant declarations, pseudo functions and commands; including #include directives for other files. These lines are general purpose code line and may or not may #included by more than one .prg files.
For example, say we have some values like :
pi := 22 / 7 MaxUserCount := 10
If we declare this constants as above in the .prg file, this two identifiers are variables.
We can declare that values in another way :
#define pi 22 / 7 #define MaxUserCount 10
In this case this two identifiers are constant, so their values has been fixed, no changeable afterward. #define is a pre-processor directive, these two identifiers are meta-constants and can be use in the code (.prg) file, after defined place ( if defined at top of file, can be use anywhere in that file).
I we want use that two value into other code (.prg) files, we need repeat above two lines (consider a quite large list) for all that code (.prg) files. And of course when a modification required, we need edit all code files.
In this case we build a .ch file that contains that definitions and add an #include directive to code files that need this definitions.
.ch file extension is a general tradition and doesn’t implies any specific action to compiler.
What is Pre-processor and how it works ?
The Pre-processor is a translation program that prepares source code for compilation by applying pre-defined text replacements. The replacements to be made are specified by directives in the source file. The preprocessor operates transparently as a part of the compilation process.
First phase of of compilation process is pre-processing. The portion of compile engine that perform pre-processing phase is called pre-processor.
Before the later compilation phases take place, pre-processor scan the source file from top to bottom for certain directives and translate them into regular source code that can be compiled. The output of the pre-processor is then used as input to the next step of compilation. The /P compiler option can be used to write this pre-processor output (.ppo) file to disk so that you can see the source code that was used as input to the next compilation phase. This option is especially useful if you have used the #command and #translate directives to build user-defined commands. You can look at the (.ppo) file to see whether or not commands translated as you expected.
The following table summarize the pre-processor directives.
Directive Meaning -------------------- -------------------------------------------------------------- #define Define a manifest constant or pseudo-function #undef Remove a #define definition #include Include a file into the current source file #command, #xcommand, Specify a user defined command or translation #translate, directive (This four directives are same as each #xtranslate others with some minor differences) . #ifdef Compile a section of code if an identifier is defined #ifndef Compile a section of code if an identifier is undefined #error Generate a compiler error and display a message #stdout Send literal text to the standard output device
Here you can find pre-processor terms.