ca********@yahoo.com wrote:
hi
I recently came across a C program, a snippet of which is as follows:
unsigned long get_sp(void)
{
__asm__("movl %esp,%eax");
}
int main(int argc,char **argv)
{
unsigned long sp;
sp=get_sp();
........
}
Is __asm__(...) a standard routine for calling assembly language
instructions in a C language program?
No, not in standard C.
As __asm__ starts with leading underscores, it is in the
implementation's namespace, i.e. it is an identifier you should
not use. The implementation may do whatever non-standard things
it needs in order to get its job done (that is, compiling your
standard compliant code into an executable) and sometimes it
lets you access these things, too.
The C99 standard mentions the use of an "asm" keyword as common
extension, so you also might encounter
asm(....)
instead of the above -- or anything else.
All that is not portable and not standard C.
Cheers
Michae
--
E-Mail: Mine is a gmx dot de address.