This is a common trick to make a โreference typeโ in C, where using it as an argument to a function causes one element array to degrade to a pointer to its first element without the need for a programmer to explicitly use the & operator to get its address. If declared, this is the real type of the stack (dynamic allocation is not required), but when passed as an argument, the called function receives a pointer to it, not a copy, so it went cheap (and can be changed by the called function if there is no const ).
GMP uses the same trick with its type mpz_t , and it is critical there because the structure controls a pointer to dynamically allocated memory; The mpz_init function relies on getting a pointer to a structure, not a copy of it, or cannot initialize it at all. Similarly, many operations can change the size of dynamically allocated memory, and this will not work if they cannot change the structure of the calling object.
ShadowRanger Nov 02 '17 at 23:56 on 2017-11-02 23:56
source share