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

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

Re: [avr-gcc-list] Comma Operator in #define


From: David Gay
Subject: Re: [avr-gcc-list] Comma Operator in #define
Date: Wed, 23 Jul 2003 15:13:21 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030314

Bernd Trog wrote:
On Wed, 23 Jul 2003, Keith Gudger wrote:
I have had problems with inline functions in IAR - what should I watch out
for in GCC?

For example, this code compiled with gcc-3.2.1:
-----------------------------------------------------------
#define PORTD 0x12
static
inline
void
write_byte( unsigned char adr, unsigned char data )
{
    asm("out %0, %1" : : "I" (adr), "r" (data)  );
}

int main(void)
{
  write_byte( PORTD, 4);
  return 0;
}
-----------------------------------------------------------

but not with gcc-3.3 :-(

Well you are asking it to do something which may not be possible (inline is a hint, not an order, and if write_byte isn't inlined then the asm statement will have a problem). That said, a fix didn't take too long to find (observant eyes will notice the const on the adr parameter):

#define PORTD 0x12
static
inline
void
write_byte( const unsigned char adr, unsigned char data )
{
    asm("out %0, %1" : : "I" (adr), "r" (data)  );
}

int main(void)
{
  write_byte( PORTD, 4);
  return 0;
}


It's not ideal as you still get a warning:
avr-gcc -c -S -O foo.c
foo.c: In function `write_byte':
foo.c:7: warning: asm operand 0 probably doesn't match constraints


And if you compile without -O it fails (because it doesn't inline without -O...):
avr-gcc -c -S foo.c
foo.c: In function `write_byte':
foo.c:7: warning: asm operand 0 probably doesn't match constraints
foo.c:7: error: impossible constraint in `asm'

This is with a May version of avr-gcc 3.3 (hopefully the released one behaves the same way...):
avr-gcc -v
Reading specs from /usr/lib/gcc-lib/avr/3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,c++ --disable-nls --target=avr i386-redhat-linux
Thread model: single
gcc version 3.3 20030512 (prerelease)

David Gay
address@hidden



reply via email to

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