jacob navia said:
__declspec(naked) [...]
This allows
o To write interrupt handlers and similar in assembly
No it doesn't, unless your compiler also has an extension that allows you to
write in assembly. Do you think that such an extension should be
standardized, too?
(I think he means "in C", but yes, you usually need such an
extension to add some sort of "return from interrupt" instruction
at the end, of course.)
This is a horrible syntax to define an alias name for a function. Do you
think it could be used for anything else, with portably defined semantics?
It is certainly "ugly" (to me), although I have never seen a "pretty"
(to me) method. (Methods I have seen include inline assembly,
various forms of pragma, and putting various instructions in a
separate linker file. The last one is the "cleanest" in various
senses, but runs an extra risk due to the separation of the source
code and link-symbol manipulation.)
Maybe because it's impossible to specify its semantics without making a lot
of assumptions about how the compiler works?
I suspect Mr Navia will now rail against you like he does against
me, at time.
Seriously, as an example of what might go wrong, one should
consider the following cleaned-up assembly that is the result
of compiling the following three-line C source:
int foo(void) { return 42; }
char *bar(void) { return NULL; }
void baz(int x) { }
/* results in */
bar_: .globl bar_
ori $0,$0,$1 # register 0 contains 0, so this sets r1=0
ret # and by convention r1 holds the return value
baz_: .globl baz_
ret
foo_: .globl foo_
ori $0,#42,$1 # again, r1 = 0 | 42
ret
Note that the functions have been alphabetized -- foo() no longer
comes before bar(). (This order is "luck of the draw": not deliberate
sorting, just what comes out of a table. The point is, just as
ordinary variable declarations within a function are not actually
created "in order" in a stack frame -- or even in registers -- by
an optimizing compiler, neither are the routines output "in order".
The compiler mashes things around to suit itself, then outputs
"whatever is required", not necessarily "the obvious steps, one
instruction at a time, based on the input, read one statement at
a time".)
(Real compilers really do this, and the name-aliasing method suggested
above assumes otherwise.)