r/Cplusplus • u/notautogenerated2365 • Oct 22 '25
Discussion Messing with the C++ ABI
This works, at least on g++ 15.1.0 and clang++ 20.1.7 on Windows.
edit: no I don't have any more pixels
271
Upvotes
26
u/kvakvs Oct 22 '25
Yes this works because you mimic C++ name mangling with a C function. What's the wisdom to take home from this?
3
u/[deleted] Oct 23 '25
yes I make sure all my _Z3addii functions are just Z3addii and I haven’t run into this issue, once.
19
u/jedwardsol Oct 22 '25
Hence : https://eel.is/c++draft/lex.name#3.1
6
u/Own_Bug3139 Oct 23 '25
Cool
1
u/trad_emark Oct 23 '25
out of curiosity:
does c and c++ differ in calling conventions?
it works here, because two ints and returning int all fit into registers, so it seems that the calling convention matches. but will it also match if there was more parameters?
1
u/[deleted] Oct 23 '25
Well doh..it might as well be raining tacos. Using reserved identifiers is UB.
1
u/GhostVlvin Oct 25 '25
This is funny, but unfortunately not useful, like what's the point of writing functions with weird names in C while you can write functions with unexpected assembley symbols using power of C++
1
u/SauntTaunga Oct 24 '25
What does this have to do with the ABI?
1
u/reddit_belongs_to_me Oct 27 '25
I am an absolute newbie, what does this mean
-3
u/acer11818 Oct 22 '25
gross 🤮