[previous] 0842 [next] Using #define or #undef inside a function.
Preprocessing REFERENCE - ISO:C90-6.8.3.5 Scope of Macro Definitions

A macro is being #define'd or #undef'd within the scope of a function.

It is quite legal to place #define and #undef directives anywhere in source code because macros are not subject to scoping rules like other identifiers. A macro definition is effective only following the point of definition in the source code. However it can be considered good practice to use #define and #undef directives only at the top of a source file (i.e. at file scope) to avoid any possible confusion.

For example:


/*PRQA S 2017,3205,3408 ++*/

extern void foo( void )
{
#define M1 10                   /* Message 0842 */
    int x = M1;
    /* ... */
#undef M1                       /* Message 0842 and 0841 */
    /* ... */
}

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents