Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there two ways to write inline assembly with gcc?

Tags:

gcc

asm volatile(...);

__asm__ __volatile__(...);

I see both are used; why create some duplicate stuff?

like image 546
new_perl Avatar asked Oct 09 '22 16:10

new_perl


1 Answers

The C standard reserves 'asm' for use by users for any purpose. Therefore, GCC provides the __asm__ notation to avoid running into the user's name space (because identifiers starting with double underscore are reserved for the implementation).

The notation with the double underscore is ungainly, so GCC provides the pleasanter interface without the double underscores. But if you turn on a standard-compliant compilation mode (such as -std=c99), the asm option is turned off. By writing with the double underscore notation, it is always available.

So, asm is pleasanter to read, but __asm__ is compliant with the C standard.

like image 79
Jonathan Leffler Avatar answered Oct 13 '22 11:10

Jonathan Leffler