Page MenuHomeFreeBSD

Document two new conventions:
AbandonedPublic

Authored by imp on Jan 9 2020, 10:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 8 2023, 5:33 AM
Unknown Object (File)
Nov 7 2023, 4:01 AM
Unknown Object (File)
Oct 11 2023, 10:36 PM
Unknown Object (File)
Oct 7 2023, 4:27 AM
Unknown Object (File)
Oct 6 2023, 2:56 AM
Unknown Object (File)
Aug 23 2023, 1:59 PM
Unknown Object (File)
Aug 22 2023, 12:53 PM
Unknown Object (File)
Mar 4 2023, 10:49 AM

Details

Summary

C99 initializers have been encouraged for a while.
_Static_assert is to be preferred to CTASSERT.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 28583
Build 26625: arc lint + arc unit

Event Timeline

julian requested changes to this revision.Jan 9 2020, 10:21 PM
julian added a subscriber: julian.
julian added inline comments.
share/man/man9/style.9
902

.. e.g. (example)..
so people don't have to go look it up to see what it is.

This revision now requires changes to proceed.Jan 9 2020, 10:21 PM

I'd rather see use switch to static_assert since that's in C11 and C++11. It's a bit unfortunate that only C++17 has the single argument version though.

rlibby added inline comments.
share/man/man9/style.9
896–900

Just my opinion: _Static_assert() is longer, uglier, and the mandatory second argument is often not useful (since it's just a string, and not e.g. a printf format). It feels weird to have regular code directly invoking reserved identifiers (underscore capital), like directly using _Bool. I'd suggest we consider just leaving CTASSERT() alone and maybe adding a new CTASSERT1() wrapper.

share/man/man9/style.9
896–900

I'd second this: _Static_assert() looks weird as it feels like reserved macro. Additionally, having a macro able to provide an error explanation directly without encoding it in the comments is pretty useful. I'd prefer either sticking with static_assert() or introducing CTASSERT1() wrapper.

From here: https://en.cppreference.com/w/c/error/static_assert it seems that the intention is that _Static_assert should be used publicly as static_assert() from <assert.h>. (Our assert.h defines it). This is indeed similar to _Bool vs bool where a header is used in userland (<stdbool.h>) to give the C++ name in C. What we have one for 'bool' in the kernel is to go ahead and define 'bool' in <sys/types.h> under #ifdef _KERNEL. I think something similar is probably ok in in <sys/systm.h> where we define 'static_assert' to '_Static_assert' and fix existing kernel code to use the C++ spelling.

I agree with @jhb, we should prefer static_assert using assert.h