views:

530

answers:

3

I'm now willing to compile my project with -std=c99 and I'm facing an error I'm not understanding for the moment. This line :

my_type* td = ({ register kmy_type* arg0 asm("eax"); arg0; });

gives me the following error only in C99 :

warning: ISO C forbids nested functions
error: syntax error before ‘asm’
error: ‘arg0’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
warning: ISO C forbids braced-groups within expressions

Any clues are welcome to help me understanding what this means. I didn't write this line and I'm also not sure to understand what is its purpose.

A: 

The problem there is not asm, looks like its arg0

Arkaitz Jimenez
No, the problem is asm; arg0 is just a variable with declaration containing asm, therefore the compiler is confused about it.
jpalecek
A: 

asm() doesn't seem to work with -std=c99. It's a bad idea in my opinion, since the standard actually suggests that compilers support an asm() keyword, but it isn't mandatory.

I suggest that you use -pedantic instead.

Bastien Léonard
+5  A: 

The line

my_type* td = ({ register my_type* arg0 asm("eax"); arg0; });

should get a value in the eax register, interpreted as a pointer, into td variable. However, it uses lots of GNU extensions, particularly statement expressions and this use of asm (explicit register allocation). I'd suggest you to switch to -std=gnu99 (or whatever it's called). Otherwise, you might want to play with double underscores (eg. asm -> __asm) or the __extension__ keyword, but I don't know if it'll help in c99 mode.

Edit: I just tried it and simply changing asm to __asm works.

jpalecek
Thanks - I just ran into this problem as well. It's not obvious that C99 is the problem!
Blank Xavier