gasilmega.blogg.se

Max macro in c
Max macro in c










max macro in c

To create a macro to guard against duplication, an #ifndef directive first tests to see if the definition has already been made by another header file included in the same program. For instance, myfunction.h is represented as MYFUNCTION_H. The name is an uppercase version of the file name, with the dot changed to an underscore. This creates a unique macro name for each header file. The solution to this problem of redefinition is to use preprocessor directives to ensure the compiler will only be exposed to a single definition, so called inclusion guards. This can cause duplication where definitions appear in two files. h header files, and the header files may contain one or more #include directives to make other classes or functions available from other header files.

max macro in c

#Max macro in c code

To test multiple definitions, the #ifdef macro can be expressed as #if defined and additional tests made #elif defined macros.Ī C++ code usually has many. The macro can then be redefined by using #define directive again. When that test returns true, it will do insert up the a corresponding #endif directive.Īny previously defined macro can be removed later using the #undef directive so that subsequent #ifdef conditional tests fail. On the other hand, the #ifndef directive tests to see if a specified macro has not been defined.

max macro in c

When the macro has been defined, so the test returns true, the preprocessor will do insert on subsequent lines up to a corresponding #endif directive. The #ifdef directive performs the most common preprocessor function by testing to see if a specified macro has been defined. #ifdef, #ifndef, #if defined, #else, #elif defined For numeric substitution in expression the macro name should be enclosed in parentheses to ensure correct precedence. As with constant variable names, the macro name uses uppercase, and defined string values should be encolsed within double quotes. Similar to #include preprocessor directives, #define directives can appear at the start of the source code. The #define directives specifies a macro, comprising an identifier name and a string or numerics, to be substituted by the preprocessor for each occurance of that macro in the source code.Ĭout << STARS << endl << SITE << endl << STARS Ĭout << endl << "Next YEAR is: " << ((YEAR)+1) << endl Other preprocessor directives can be used to substitute test or numerics before assembly and compilation. In the previous section, we saw the preprocessor substitutes library code for #include directives.












Max macro in c