tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: major/minor(3) macros conflict with regular code
On Thu, Feb 06, 2025 at 11:48:48PM +0100, Anthony Mallet wrote:
> Hi,
>
> I have some code that defines these methods in a C++ class:
> int32_t major() const
> int32_t minor() const
> (for the context: this is in protobuf generated code from a message
> that has major/minor fields).
>
> The generated code fails to compile because it conflicts with major(3)
> macro and minor(3) macros from sys/types.h:
>
> #define major(x) ((devmajor_t)(((uint32_t)(x) & 0x000fff00) >> 8))
> #define minor(x) ...
>
> Do major(3) and minor(3) really need to be macros?
I think maybe a better question is: do they really need to be in
<sys/types.h>? They seem like the kind of thing that more properly
belongs in <sys/param.h>, whether or not that's traditional.
(Standards have things to say about the namespace pollution allowed to
<sys/types.h>, but even regardless of that it's supposed to be
reasonably safe to add <sys/types.h> to virtually any source file.)
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index