![]() ![]() If you as a consumer of the services of The Implementation try to use or define a name reserved to the implementation, you must be aware that your code will probably break sooner or later, and that it will be your fault, not the fault of The Implementation. The Implementation is allowed to define macros for any purpose it desires or needs, of any type (function-like or object-like) it desires or needs, provided those names are reserved to the implementation. This is one of the reasons why the standard is careful to define which namespaces are reserved for 'The Implementation'. And there's no protection from the macro. ![]() This code defines a bogus function that's called min and is nonsensical. This is done with double scan, you can read more about it at C Preprocessor tricks, tips, and idioms. Think about it - what is the function really called? Here I am going to describe three different methods of getting the result of expanded macro evaluation. Had the macro been an argument-less object-like macro, the trick would not work: #define nonsense min In the function definition line, the token after 'nonsense' is a close parenthesis, so it is not an invocation of the nonsense macro. This is because a macro invocation - for a function-like macro - must be immediately followed by an open parenthesis (give or take white space, possibly including comments). The function nonsense() is defined fine, despite the macro immediately before it. One other trick is available - if the macros are function-like macros and not object-like macros. ![]() If the macros are not defined in a header, of course, you are stuck until you refactor the code so that they are in a header. A macro is a small piece of code or constant value that is replaced with C source code before the execution of a C program. The Visual Expansion will enable you to visualize the preprocessor passes of the expansion. The macro and its parameters should be enclosed in parentheses. When you hover over a macro, you can access Quick Info, which now includes the Visualize Expansion link in addition to the Copy and Expand Inline options. The problem is there is no 're-enable' mechanism.Īs others have pointed out, if the header file containing the macro definitions is structured so that it does not contain any typedef or enum declarations (these cannot be repeated function and variable declarations can be repeated), then you could #undef the macro, do what you need without the macro in effect, and then re-include the header, possibly after undefining its protection against reinclusion. The analyzer has detected a potentially incorrect macro definition. Using just the facilities defined by Standard C (C89, C99 or C11), the only 'disable' mechanism is #undef. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |