[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-devel] [bug #35875] #define ⇒ enum?
From: |
Bill Auerbach |
Subject: |
Re: [lwip-devel] [bug #35875] #define ⇒ enum? |
Date: |
Mon, 19 Mar 2012 09:54:27 -0400 |
>-----Original Message-----
>On Behalf Of David Brown
>Sent: Monday, March 19, 2012 8:01 AM
>Subject: Re: [lwip-devel] [bug #35875] #define ⇒ enum?
>
>Using enum types for the values can cause warnings if you use a compiler
>and warnings that check for mixes between enumerated types and integers,
>or if you compile in forced C++ mode. So while using enum types is good
>in some ways, it may mean extra explicit casts to make the code compile
>cleanly in all cases.
Although this is strictly true, in practice any decent compiler will not
promote a constant to an int if it is used in a way that allows the same
correct result by not promoting. A compiler that can generate an 8-bit
compare of a char to a constant compare probably would do this (and IMO
isn't very good if it doesn’t).
I think on most compilers changing to enum will make the code size slightly
larger. It should improve things in a debugger which (again if good) if it
will show the enum member name when viewing an enum variable. I've seen a
compiler with a compiler option use an 8-bit enum when all of the members
fit in 8-bits - I don't know if any mainstream compilers do this.
>An alternative might be to use "static const u8_t" values rather than
>"#define" macros, but again there could be problems with warning-free
>compiles if the values are used in several places.
And a compiler is not prevented by the standard from created storage for
this IIRC.
Bill
- [lwip-devel] [bug #35875] #define ⇒ enum?, Markus Elfring, 2012/03/17
- [lwip-devel] [bug #35875] #define ⇒ enum?, Simon Goldschmidt, 2012/03/18
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?, David Brown, 2012/03/19
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?,
Bill Auerbach <=
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?, David Brown, 2012/03/19
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?, Simon Goldschmidt, 2012/03/19
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?, David Empson, 2012/03/19
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?, Bill Auerbach, 2012/03/19
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?, David Empson, 2012/03/20
- Re: [lwip-devel] [bug #35875] #define ⇒ enum?, Bill Auerbach, 2012/03/19
[lwip-devel] [bug #35875] #define ⇒ enum?, Kieran Mansley, 2012/03/20