Historical systems used macros and did not have such enumerations.
Older versions of POSIX / Single Unix (such as SUSv3 ) require that SOCK_xxx
be macros. This means that these constants can be used in preprocessor directives (for example, #ifdef SOCK_DGRAM
). Sometimes it can be useful to check during assembly whether the system supports a non-standard socket type.
Newer standards (for example, SUSv4 ) have softened this requirement in the system: the constants SOCK_xxx
can be any symbolic constants . This includes preprocessor macros, as well as any other definition that creates a constant expression (suitable for static initializers and other contexts requiring a constant expression), such as enumeration constants.
The execution that you are looking for conformance to SUSv3 (and SUSv4, SUSv3, implies conformity to SUSv4 in this regard). An implementation that defined only the enumeration, not the constants, would be compatible with SUSv4, but not with SUSv3.
The advantage of defining an enumeration is that it allows the compiler to give decent feedback if the SOCK_xxx
constant SOCK_xxx
used in a context that does not call it, or if an arbitrary integer is used where the SOCK_xxx
value SOCK_xxx
expected.
The same applies to many similar sets of constants.
source share