|
Re: #define's scope?
Actually #define works from the place where it was defined to any other files being processed afterwards.
This is why you typically have the following statement in a header file:
#ifndef _GYRO_H
#define _GYRO_H
{code}
#endif
What this does is tell the pre processor to only compile each header file once... so the preprocessor keeps the #define in an internal lookup table while processing files.
If you are not familiar with how compiling works here is a brief overview:
First the pre processor goes over all the files before compile time and creates a new file which conforms to what is told using #statements .... (i.e replace all instances of VARIABLE with rc_dig_in01)
You then typically have a main program, this main program may use additional functionality from other files, in order to access variables and functions from another file it uses a "header" the header is just a list of what is available.
This header is then connected to an actual C file which contains the functionality.
When the compiler compiles a single C file (whether it is main, or another file) it creates an intermediate .o file which contains assembly instructions and information for the linker on where to find functions that are referenced that are in another C file.
What the preprocessor directive i mentioned above does is prevent the same header from being re-included twice (and thus re-introducing the same variable and function names creating a conflict)
__________________
Team 701
|