avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] -fshort-enums are not so short


From: Bernard Fouché
Subject: [avr-gcc-list] -fshort-enums are not so short
Date: Wed, 24 Nov 2004 12:57:40 +0100

Hi.

Compiling with gcc 3.4.2 with -Os -fshort-enums, it appears that enums are
processed on 16 bits and not 8 when they could be on 8 bits. (when looking
at 'man gcc' it is said that this option will make the compiler use the
smallest possible type of int to process the enum, I assume that for the avr
it is 8 bits)

C code:

enum Foo { FOO_1, FOO_2 } Foo;
uint8_t v;

main()
{
  switch(Foo){
  case FOO_1:
    v=1;
    break;
  case FOO_2:
    v=2;
    break;
  }
}

compilation result:

000000ca <main>:
enum Foo { FOO_1, FOO_2 } Foo;
uint8_t v;

main()
{
  ca:   cf ef           ldi     r28, 0xFF       ; 255
  cc:   d0 e1           ldi     r29, 0x10       ; 16
  ce:   de bf           out     0x3e, r29       ; 62
  d0:   cd bf           out     0x3d, r28       ; 61
  switch(Foo){
  d2:   80 91 02 01     lds     r24, 0x0102
  d6:   99 27           eor     r25, r25
  d8:   00 97           sbiw    r24, 0x00       ; 0
  da:   19 f0           breq    .+6             ; 0xe2
  dc:   01 97           sbiw    r24, 0x01       ; 1
  de:   19 f0           breq    .+6             ; 0xe6
  e0:   05 c0           rjmp    .+10            ; 0xec
  case FOO_1:
    v=1;
  e2:   81 e0           ldi     r24, 0x01       ; 1
  e4:   01 c0           rjmp    .+2             ; 0xe8
    break;
  case FOO_2:
    v=2;
  e6:   82 e0           ldi     r24, 0x02       ; 2
  e8:   80 93 01 01     sts     0x0101, r24
    break;
  }
}
...



reply via email to

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