| ▲ | mFixman 3 hours ago | |||||||
I used to slay with this in code golfing competitions from TopCoder, where you had to implement a function to solve a particular problem, thanks to C pointer maths and the gcc generally putting function arguments in order in the stack. Turns out, these two are equivalent in practice (but UB in the C++ standard): | ||||||||
| ▲ | mananaysiempre 2 hours ago | parent | next [-] | |||||||
> Turns out, these two are equivalent in practice Not in the x86-64 SysV ABI they aren’t. The arguments will be passed in registers (yes, even the variadic ones), so how your compiler will interpret 1[&a] is anybody’s guess. (For me, x86_64-unknown-linux-gnu-g++ -O2 yields, essentially, return a+a+a+a; which is certainly an interpretation. I’m also getting strange results from i686-unknown-linux-gnu-g++ -O2, but my x87 assembly is rusty enough that I don’t really get what’s going on there.) | ||||||||
| ▲ | camel-cdr 3 hours ago | parent | prev | next [-] | |||||||
K&R syntax is -1 char, if you are in C: | ||||||||
| ▲ | Joker_vD an hour ago | parent | prev [-] | |||||||
The cast in the invocation can be macro-ed away. And the best thing is, the actual stack layout and data movement/shuffling is pretty much identical to the approach with <stdargs.h>, and with no UB or compiler intrinsics. | ||||||||
| ||||||||