In: Electrical Engineering
What does the following statement tell a C compiler to do, and
when does it do it?
#define UCHAR unsigned char
#define is a C preprocessor directive used to define macros.
A preprocessor directive is a program statement which is invoked before the program compilation takes place. Any line followed by a # character is a preprocessor. This includes the include drective as well. The preprocessor directives are used to provide general instruction or required data which is used inside a program.
A macro is a block of code which has been given a name. Any occurance of that name is replaced by the value of the macro. Say, I defined macro named UCHAR who's value is unsigned char. Now every time the word UCHAR is used in the program it is replaced by nsigned char before compilation. In contrast to variables, where data is actually stored inside of them, macros act rather like alias names.
by the statement #define UCHAR unsigned char, Any occurance of UCHAR will be replaced by unsigned char. This job is done by the preprocessor and then handover to compiler to do its job i.e to convert a program from a human-readable format into a machine-readable format.