Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #150300
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: clarification about enums in C |
| Date | 2020-02-27 15:05 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <877e08vzng.fsf@bsb.me.uk> (permalink) |
| References | <aaf0f57f-4ae1-4c4a-a0aa-314eade48440@googlegroups.com> <r35hab$ts9$1@dont-email.me> <5c585469-72c8-42f8-9e74-848f160db602@googlegroups.com> <r37vss$f30$1@dont-email.me> <87imjst80s.fsf@nosuchdomain.example.com> |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> David Brown <david.brown@hesbynett.no> writes:
> [...]
>>> enum enum_t {
>>> uns = (unsigned)-1,
>>> neg = -1,
>>> };
>>> Both in gcc and in clang uns has type 'unsigned int' rather than 'int'.
>>> And indeed it differs from type of 'enum_t' which in ths case is 'int'.
>>
>> This is an extension that these tools support - as do many compilers.
>> If you want to ensure that you stick to standards-only code, use
>> "-Wpedantic" (along with your choice of -std=c11, -std=c99 or -std=c90),
>> and pay attention to the warnings. The C standard does not say how
>> "uns" should be treated, gcc's extensions do the "obvious" thing.
>
> Ah, but gcc doesn't print a diagnostic with "-std=c11 -Wpedantic", even
> though the code violates a constraint.
Oh. It does for me:
$ cat enum.c
enum enum_t {
uns = (unsigned)-1,
neg = -1,
};
$ gcc -std=c11 -Wpedantic -c enum.c
enum.c:2:12: warning: ISO C restricts enumerator values to range of ‘int’ [-Wpedantic]
uns = (unsigned)-1,
^
$ gcc --version ✘
gcc (Ubuntu 8.3.0-6ubuntu1) 8.3.0
<cut>
> Even my copy of gcc built from source that calls itself
> gcc (GCC) 10.0.0 20200111 (experimental)
> fails to diagnose it.
>
> A recent version of clang does print a diagnostic.
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
clarification about enums in C Thiago Adams <thiago.adams@gmail.com> - 2020-02-25 15:38 -0800
Re: clarification about enums in C luser droog <luser.droog@gmail.com> - 2020-02-25 19:19 -0800
Re: clarification about enums in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-02-25 21:17 -0800
Re: clarification about enums in C Thiago Adams <thiago.adams@gmail.com> - 2020-02-27 04:01 -0800
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-26 11:29 +0100
Re: clarification about enums in C already5chosen@yahoo.com - 2020-02-26 14:05 -0800
Re: clarification about enums in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-26 23:03 +0000
Re: clarification about enums in C already5chosen@yahoo.com - 2020-02-26 23:29 -0800
Re: clarification about enums in C already5chosen@yahoo.com - 2020-02-27 01:42 -0800
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-27 11:02 +0100
Re: clarification about enums in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-27 06:37 -0800
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-27 16:18 +0100
Re: clarification about enums in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-02-27 23:24 -0500
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-27 09:50 +0100
Re: clarification about enums in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-27 06:33 -0800
Re: clarification about enums in C already5chosen@yahoo.com - 2020-02-27 06:53 -0800
Re: clarification about enums in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-27 15:05 +0000
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-27 16:24 +0100
Re: clarification about enums in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-28 01:27 -0800
Re: clarification about enums in C already5chosen@yahoo.com - 2020-02-27 01:29 -0800
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-27 11:12 +0100
Re: clarification about enums in C already5chosen@yahoo.com - 2020-02-27 03:09 -0800
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-27 14:33 +0100
Re: clarification about enums in C already5chosen@yahoo.com - 2020-02-27 05:44 -0800
Re: clarification about enums in C David Brown <david.brown@hesbynett.no> - 2020-02-27 14:57 +0100
Re: clarification about enums in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-27 11:53 +0000
Re: clarification about enums in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-02-27 23:52 -0500
Re: clarification about enums in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-28 01:30 -0800
Re: clarification about enums in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-26 14:09 +0000
Re: clarification about enums in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-02-26 09:47 -0800
Re: clarification about enums in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-02-26 21:04 +0000
csiph-web