Here is an example for what I mean:
int open(const char *pathname, int flags);
and from the man page. Looking into Linux, it is obvious the flags are bit markers.
I am curious by the use of an int as a way to set specific bits, as I had thought that the most "portable" and recommended way to do this is to use an unsigned int of specific size, perhaps uint32_t.
Does anyone have any insight as to why this is? This is a purely educational question and I am asking out of curiosity.
If I remember correctly from Unix V7, there were only 3 values allowed for the open() flags: 0 (read) 1 (write) and 2 (read-write). So, at that time, this was not a "flag" but a "mode" taking an enumeration of 0, 1, 2 : hence the "int" type.
If these where really flags, logically O_RDONLY could not be 0 and O_RDWR should be equal to O_RDONLY|O_WRONLY, which is not the case.
Later, when other flags were added, the type was kept "int" to avoid breaking the compilation of existing code when using severe control of the warnings.