[TUHS] #defines and enums

ron at ronnatalie.com ron at ronnatalie.com
Thu Nov 14 05:15:14 AEST 2019

> BTW, I'm doing my first messing around with the Linux kernel these days;
> if anyone knows the guts of the generic filesystem code I could use a bit
> of help.  Here's something that I came across on the way in <sys/mount.h>:
> enum
> {
>   MS_RDONLY = 1,		/* Mount read-only.  */
>   MS_NOSUID = 2,		/* Ignore suid and sgid bits.  */
>   MS_NODEV = 4,			/* Disallow access to device special files.  */
> ...
> };
> Can anyone explain the value of this programming style?  Is this just an
> example of the result of how programming is taught today?

This really is more a C question than a UNIX one.    The problem is that
the preprocessor macros are really kind of a kludge.   Making things
either enums (or in later C/C++ const int definitions) is a lot cleaner.  
 The #define is just probably backwards a compatibility kludge (for people
using things like MS_RDONLY or whatever in other macros).

More information about the TUHS mailing list