The example below runs as expected, but it compiles with warnings from the MACRO expansion. Im trying to create a macro that handles them both. define c 299792458 // speed of light Here, when we use c in our program, it is replaced with 299792458. Macros are the names of text/ literal values/ string (constant values) or code fragment, which will expand when pre-processor processes the macro. My TLV structure can hold string or integer. You can define a macro in C using the define preprocessor directive. I am programming the AT91SAM7X256 from Atmel and I am a little confused by the macros that define registers and how to use them. Here the trouble is that I don't want that space between Group and 0 because I need to use CLASS_NAME to create some class out of it such as class CLASS_NAME : public.īut if I use one wrapper macro to call that one, it works. During translation, all preprocessing directives ( define, include, etc.) are executed before any macro expansion occurs, so if a macro expands into a preprocessing directive, it wont be interpreted as such - it will be interpreted as (invalid) source code. A macro is a fragment of code that is given a name. In first case, after expanding MACROCOMBINEINNER you get: ABCLINE which turns into ABCLINE, because LINE is not a separate token here. However, I cannot find a way to generate the rest from that MACRO.Ĭout << "CLASS_NAME = " << CLASS_STR << endl 1 Answer Sorted by: 2 Order of expansion plays role here, first the outlier macro is expanded, then inner ones. In any kind of header file, the macro name should contain the name of the file and some additional text, to avoid conflicts with other header files. I don't want students to modify much but only that one group number defined somewhere as #define GROUP_NUM 0 ![]() ![]() I have to let CS students modify a group number and then generate some stuff related to that number.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |