MISRA Discussion Forums
MISRA rule 7.1 Octal constants vs. Linux permissions - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.7 Constants (https://forum.misra.org.uk/forumdisplay.php?fid=34)
+---- Thread: MISRA rule 7.1 Octal constants vs. Linux permissions (/showthread.php?tid=874)



MISRA rule 7.1 Octal constants vs. Linux permissions - tharris - 25-01-2012

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-permissions.shtml#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 - William Forbes - 08-02-2012

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 - misra-c - 20-02-2012

As suggested by William Forbes, a deviation would be appropriate in this situation. The suggestion to use macros is a good one.