MISRA rule 7.1 Octal constants vs. Linux permissions

6.7 Constants

Moderators: misra-c, david ward

tharris
Posts: 2
Joined: Tue Jan 23, 2007 3:30 pm

MISRA rule 7.1 Octal constants vs. Linux permissions

Postby tharris » Wed Jan 25, 2012 1:59 pm

MISRA rule 7.1 says don't use octal constants, and gives good reasons.
But code which sets and uses constants which represent Linux file permissions (see, for example, ), are necessarily octal and code is more readable in that case in octal -- the "native" format for such constants.

Of course an octal number can be written, with the same digits, as hexadecimal, and that would meet the MISRA constraint. But IMHO would not meet the spirit of this rule, which is to avoid writing digits outside the base of the number by mistake. Writing a Linux file permissions constant as hex would mean that by mistake the developer could write a digit between 8 and F, and static analysis (compiler etc) would not catch it because it's legal hex. But illegal file permission digit.

Would people see this as a good place for a deviation from MISRA rule 7.1?

William Forbes
Posts: 29
Joined: Wed Dec 17, 2008 9:48 pm
Company: TRW Automotive

Re: MISRA rule 7.1 Octal constants vs. Linux permissions

Postby William Forbes » Wed Feb 08, 2012 10:38 pm

I would say so.
BTW
0007 = 0x0007
0077 = 0x003F
0777 = 0x01FF
Not nearly so nice!

Much better would be to create some Macros!

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

Re: MISRA rule 7.1 Octal constants vs. Linux permissions

Postby misra-c » Mon Feb 20, 2012 12:16 pm

As suggested by William Forbes, a deviation would be appropriate in this situation. The suggestion to use macros is a good one.
---
Posted by and on behalf of
the MISRA C Working Group


Return to “6.7 Constants”

Who is online

Users browsing this forum: No registered users and 1 guest