MISRA Discussion Forums

Full Version: MISRA rule 7.1 Octal constants vs. Linux permissions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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-perm...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?
I would say so.
BTW
0007 = 0x0007
0077 = 0x003F
0777 = 0x01FF
Not nearly so nice!

Much better would be to create some Macros!
As suggested by William Forbes, a deviation would be appropriate in this situation. The suggestion to use macros is a good one.