|
|
|
|
|
by zackoverflow
917 days ago
|
|
> Note that the context pointer came after the “standard” arguments. All things being equal, “extra” arguments should go after standard ones. But don’t sweat it! In the most common calling conventions this allows stub implementations to be merely an unconditional jump. I didn't know this. Does this optimization have a name? Where can I read more about it? |
|
If you write
then *a is in already in the correct slot (the RDI register) for the first argument when free_with_extra_args is being called. Whatever is put into *b is never touched. If you compile this with gcc -O2 you get If you make the function call free(b) instead, you'll have to move b into the right place before calling free: This is on x86-64 as summarized here https://en.wikipedia.org/wiki/X86_calling_conventions#System...Wikipedia also has a nice summary of calling conventions on other platforms like ARM. All modern calling conventions are similar: pass the first args in registers and then use the stack as needed https://en.wikipedia.org/wiki/Calling_convention