Page 1 of 1

MISRA rule 7.1 Octal constants vs. Linux permissions

Posted: Wed Jan 25, 2012 1:59 pm
by tharris
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, http://www.zzee.com/solutions/linux-per ... ml#numeric), 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?

Re: MISRA rule 7.1 Octal constants vs. Linux permissions

Posted: Wed Feb 08, 2012 10:38 pm
by William Forbes
I would say so.
BTW
0007 = 0x0007
0077 = 0x003F
0777 = 0x01FF
Not nearly so nice!

Much better would be to create some Macros!

Re: MISRA rule 7.1 Octal constants vs. Linux permissions

Posted: Mon Feb 20, 2012 12:16 pm
by misra-c
As suggested by William Forbes, a deviation would be appropriate in this situation. The suggestion to use macros is a good one.