> This does not work if I use this code:
> ------------------------------------------------------------------------------
> /*
>   endian.c
> */
> #include <stdint.h>
> 
> static inline uint16_t endian16(uint16_t v)
> {
>   asm("swpb %0" : "+g" (v));
>   return v;
> }
> 
> volatile uint16_t value;
> int main()
> {
>   value = 0x1122;
>   endian16(value);
> 
>   //At this point: value = 0x1122 !!!!
>   return (int)value;
> }//main

>
> And I compile using:
> 
> msp430-gcc -g3 -mmcu=msp430x149 -o endian.msp endian.c -Wall -O2
> 
> The function 'endian16' (with or without __attribute__((const))) compile to
> nothing!! Maybe a problem of mspgcc with inline assembler in static inline
> functions? I work with msp430-gcc 3.2.3 compiled from CVS (2006-04-10).

No, the problem is that you're not using the return value.  When it's
declared __attribute__((const)), you're promising that the return value
is the only effect of calling the function, so GCC obviusly deletes it.

Change that to
        value = endian16(value);
and all will be well.

Note that the use of "volatile" means that the output won't be terribly
optimal.

Reply via email to