Identifiers major and minor are often already taken in POSIX systems due to their presence in <sys/types.h> as part of the makedev library function.
- Linux: https://man7.org/linux/man-pages/man3/makedev.3.html
- FreeBSD: https://man.freebsd.org/cgi/man.cgi?query=makedev
Recent versions of glibc have moved this definitions from <sys/types.h> to sys/sysmacros.h, so newer systems may not be impacted. From the Linux link above:
Depending on the version, glibc also exposes definitions for these macros from <sys/types.h> if suitable feature test macros are defined. However, this behavior was deprecated in glibc 2.25, and since glibc 2.28, <sys/types.h> no longer provides these definitions.
In particular Ubuntu 18.04 LTS (albeit a bit old now) still provides them in <sys/types.h> along with a loud warning. Ubuntu 22.04 LTS does not have this problem. I have not been able to test it on 20.04 LTS.
Other systems, such as FreeBSD still use <sys/types.h> so there is not much we can do I think. I have verified that the issue happens on a VM running FreeBSD 13.2.
I initially considered doing:
#if defined(major) #undef major #endif #if defined(minor) #undef minor #endif
but on a second thought I preferred the longer route of avoiding those identifiers entirely.
nit: camel case