lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] PPP LCP Phases Not Enum in 2.0.0 Beta


From: Sylvain Rochet
Subject: Re: [lwip-devel] PPP LCP Phases Not Enum in 2.0.0 Beta
Date: Tue, 2 Aug 2016 00:40:47 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

Hi,


On Tue, Aug 02, 2016 at 12:22:11AM +0200, Sylvain Rochet wrote:
> On Mon, Aug 01, 2016 at 09:50:30PM +0000, Greg Smith wrote:
> > Hello.
> > 
> > In Lwip 1.4.1, the PPP LCP states (phases) were all defined as an enum 
> > (typedef LinkPhase).  This made seeing the state in a debugger really 
> > nice -- it would show "PHASE_DEAD", for example. In 2.0.0 Beta1, they 
> > have been converted to #define macros.  Now the debugger only shows a 
> > number (0, for example), which isn't as convenient.
> > 
> > So:
> > 
> > 1) I'd like to understand why this change was made.
> 
> In C, an enum type is always an int, which is a 4-byte value on 32-bit 
> systems (also 4-byte on LP64, LLP64, and 8-byte on ILP64, but we are a 
> bit outside lwIP targets here). So this is to save 3 (or 7) bytes of RAM 
> per state value, and it matters.

To add a little bit information here, you made me curious about this 
subject, so, I now know about gcc -fshort-enums dangerous compilation 
option, enum __attribute__ ((__packed__)) foo, and the ":0; enum bar;
:0;" hack in struct (at least on > C90 because <= C90 only allows int 
types for bitfields).

None of them sound very appealing for me, and most of them don't even 
work, at least on gcc which I tried :-)

---------8<---------8<---------8<---------8<---------8<---------8<---------
#include <stdio.h>
#include <stdint.h>

enum toto {
        TOTO,
        TITI
};

enum toto titi;
enum __attribute__ ((__packed__)) toto titipacked;

struct tata {
        uint8_t :0;
        enum toto toto;
        uint8_t :0;
} __attribute__ ((__packed__));

int main(void) {
        printf("%lu %lu %lu\n", sizeof(titi), sizeof(struct tata), 
sizeof(titipacked));
}
---------8<---------8<---------8<---------8<---------8<---------8<--------

Returns:

$ gcc -std=c89 -Wall -std=c99 -o toto toto.c && ./toto 
4 4 4


Only -fshort-enums is actually working:

$ gcc -fshort-enums -std=c99 -Wall -std=c99 -o toto toto.c && ./toto 
1 1 1


Sylvain

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]