3 ms·
Why is taking the address of a parameter legal? Doesn't this depend on the ABI and could be a register?
by _pmf_ 5y ago
Why is taking the address of a parameter legal? Doesn't this depend on the ABI and could be a register?
- jcranmer 5y agoThe parameter is copied into a stack variable so that you can take its address in such cases.
- ximeng 5y agohttps://stackoverflow.com/questions/34519318/c-address-of-function-parameter https://stackoverflow.com/questions/34519318/c-address-of-fu... suggests it's guaranteed by the standard to be OK. In the standard at https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf https://web.archive.org/web/20181230041359if_/http://www.ope... 6.5.3.2 Address and indirection operators Constraints 1 The operand of the unary & operator shall be either a function designator, the result of a [] or unary \* operator, or an lvalue that designates an object that is not a bit-field and is not declared with the register storage-class specifier. So as the parameter is an lvalue it is guaranteed to work with the & operator.