19.13 and Assembly

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

19.13 and Assembly

Post by gs » Wed Apr 18, 2012 9:08 pm

Does the following code violate rule #19.13?

Code: Select all

#define QWER { asm ASDF #$7F; }
In this case, "$" means "value" and "#" means "address of" and is not the pasting operator.

misra-c
Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Re: 19.13 and Assembly

Post by misra-c » Wed Apr 25, 2012 12:49 pm

The # preprocessing token in this example is not an instance of the # operator (see C90 Section 6.8.3.2) because this is an object-like macro definition, i.e. there are no macro parameters. Therefore, this code complies with Rule 19.13 as well as Rule 2.1 (encapsulation of assembly language). Of course, it would still require a deviation against Rule 1.1 as the asm keyword is a language extension.

If the example had used a function-like macro definition, then the code would not be compliant with Rule 19.13 as the # token would be a # operator.
---
Posted by and on behalf of
the MISRA C Working Group

gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Re: 19.13 and Assembly

Post by gs » Wed Apr 25, 2012 5:41 pm

I am a little confused. Suppose the code reads like so:

Code: Select all

#define QWER(x) { asm x ASDF #$7F; }
In this case, the # is not applied to the macro argument. Does the mere fact a macro parameter exists in the macro definition render the macro in violation? What about

Code: Select all

#define QWER(x) { asm ASDF #$7F; }
where the parameter exists but is not used in the definition?

misra-c
Posts: 572
Joined: Thu Jan 05, 2006 1:11 pm

Re: 19.13 and Assembly

Post by misra-c » Fri Apr 27, 2012 9:35 am

The presence of a parenthesised, possibly empty, parameter list in the definition of a macro makes it a function-like macro. See the C90 standard, Section 6.8.3.

This means that all of:

Code: Select all

#define QWER(x) { asm x ASDF #$7F; }
#define QWER(x) { asm ASDF #$7F; }
#define QWER() { asm ASDF #$7F; }
are function-like macros and therefore contain instances of the # preprocessing operator.

The # preprocessing operator must be followed by a parameter (constraint C90 Section 6.8.3.2). Therefore none of the above examples is legal C.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.19 Preprocessing Directives”