1 << 31 redux

Julian Elischer julian at freebsd.org
Mon Feb 19 06:20:04 UTC 2018


On 14/1/18 1:34 am, Kyle Evans wrote:
> On Thu, Jan 11, 2018 at 6:03 AM, Eitan Adler <lists at eitanadler.com> wrote:
>> Hi all,
>>
>> A few years ago I fixed most of the cases where we used 1 << 31 in FreeBSD.
>> This expression is illegal in C. Since then the issue has arisen again.
>>
>> https://reviews.freebsd.org/D13858 fixed most of the non-contrib cases.
>>
>> I'd also like to see if we could find some more general solution, be it a
>> compiler warning, bit set macro, or otherwise.
>>
> For what it's worth, I've really come to like and appreciate NetBSD's
> approach with __BIT/__BITS. See [1] for implementation, [2] for usage.
>
> [1] http://src.illumos.org/source/xref/netbsd-src/sys/sys/cdefs.h#577

I like __BIT() but it should give a compile error if the number is too 
large rather than just setting it to 0.
in fact I think I think it should take a target and use the size of 
the target rather than assuming int.

> [2] http://src.illumos.org/source/xref/netbsd-src/sys/arch/arm/sunxi/sunxi_usbphy.c#L44
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
>



More information about the freebsd-hackers mailing list