MK.
MK.

Reputation: 4027

C function syntax

On this page : http://www.scs.stanford.edu/histar/src/pkg/uclibc/libc/sysdeps/linux/x86_64/sigaction.c

I see these two lines :

extern void restore_rt (void) asm ("__restore_rt") attribute_hidden;
extern void restore (void) asm ("__restore") attribute_hidden;

What is this syntax? Is it setting up restore_rt to be a function that has inline asm("__restore_rt") as its body?

Thanks!

Upvotes: 8

Views: 3052

Answers (2)

Using asm in a function declaration is a GCC extension (also supported by Clang/LLVM) called asm-label. It is setting the assembler and linker known name of the function.

BTW, in your code attribute_hidden is probably a macro for some function attribute, probably __attribute__ ((visibility ("hidden")))

Upvotes: 4

Buddy
Buddy

Reputation: 11038

Apparently it's a way to replace the symbolic name of a C function...

In order to change the name of a function, you need a prototype declaration, because the compiler will not accept the asm keyword in the function definition:

extern long Calc(void) asm ("CALCULATE");

Calling the function Calc() will create assembler instructions to call the function CALCULATE.

Search for "Replacing symbolic names of C functions" in this document

Upvotes: 3

Related Questions