aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/extensions.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/extensions.md b/doc/extensions.md
index 9a7b81d..9d07972 100644
--- a/doc/extensions.md
+++ b/doc/extensions.md
@@ -32,6 +32,30 @@ rules. The name may contain characters not allowed in regular identifiers.
- **`__builtin_va_list`**: Built-in suitable for implementing the `va_list` type.
- **`__builtin_va_start`**: Built-in suitable for implementing the `va_start` macro.
+### Enumerator values outside the range of `int`
+
+ISO C requires that enumerator values be in the range of `int`. GNU C
+allows any integer value, at the cost of enumerator constants possibly
+having different types inside and outside the `enum` specifier.
+
+In the following example, `A` has type `unsigned` inside the `enum`
+specifier, and `long` outside, so both of the assertions fail.
+
+```c
+enum E {
+ A = 0x80000000,
+ B = sizeof(A),
+ C = A < -1,
+ D = -1,
+};
+_Static_assert(B == sizeof(A), "sizeof(A) changed");
+_Static_assert(C == A < -1, "signedness of typeof(A) changed");
+```
+
+As a compromise, we allow enumerator values larger than `INT_MAX` and
+less than or equal to `UINT_MAX`, but only if no other enumerators have
+a negative value. This way, enumerator constants have a fixed type.
+
## Missing
### Statement expressions