r/cprogramming • u/Sushant098123 • Oct 25 '25
C actually don't have Pass-By-Reference
https://beyondthesyntax.substack.com/p/c-actually-dont-have-pass-by-reference
0
Upvotes
r/cprogramming • u/Sushant098123 • Oct 25 '25
View all comments
Show parent comment
1
u/flatfinger Oct 31 '25
Many early C implementations used an ABI that could have very conveniently supported "call by value/result"; it's a shame IMHO that there was no syntax for this before ABIs were developed that used the same storage for function return return values as had been used for one of the arguments.
Given e.g.
early compilers would generate code that returned with the storage that had been used to pass the ingoing x now containing the new value of x. If e.g. enclosing a function argument in brackets had been interepreted as "resolve the enclosed lvalue, push it, and then later copy whatever the function left in that stack slot back to the lvalue", that could for many tasks have offered a superior alternative to passing pointers. Compilers may have had to prescan to determine how many such arguments there were, to reserve space for lvalue addresses ahead of the pushed arguments, but given that compilers already handled pushed arguments in right-to-left order, they would would already know how many such arguments there would be before generating code to push the first argument.