Rule 19.4 Does "#define XY -1" violate 19.4

6.19 Preprocessing Directives

Moderators: misra-c, david ward

Post Reply
[email protected]
Posts: 1
Joined: Tue Nov 05, 2013 1:54 pm
Company: Berner&Mattner

Rule 19.4 Does "#define XY -1" violate 19.4

Post by [email protected] » Thu Mar 17, 2016 3:37 pm

Dear MISRA Team,

as I found out, 2 out of 3 commercial MISRA checking tools report the statement "#define XY -1" to be a violation of rule 19.4. I am not sure whether or not this #define actually violates rule 19.4 but if so I would not fully understand the risk associated with this particular #define statement. Could someone please help and discuss if this is a violation and why it should be avoided?

Thank your for your support!

Posts: 2
Joined: Fri Feb 05, 2016 3:04 pm
Company: General Dynamics

Re: Rule 19.4 Does "#define XY -1" violate 19.4

Post by SimonB » Fri Mar 18, 2016 11:58 am

I'm not surprised it's rejected. "-1" isn't an integer literal, it's the unary minus operator applied to a literal. This means that it's an expression and should be parenthesised.

I can't think of any cases where using it gives a surprisingly wrong answer, but it does allow things to compile that look wrong, such as:-

Code: Select all

	int b = 3 XY;

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

Re: Rule 19.4 Does "#define XY -1" violate 19.4

Post by misra-c » Fri Apr 08, 2016 8:42 am

The MISRA working group agree with the above response.
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.19 Preprocessing Directives”