1: void f(mystruct *a)
2: void f(const mystruct *a)
Does changing the function signature from 1->2 break API/ABI in C?
How about changing 2->1?
From C99 standard 6.2.5/26 "Types":
pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements.
So the ABI/API should not be affected going from 1 to 2. (The API doesn't change because a pointer to a non-const-qualified type may be converted to a pointer to a const-qualified version of the type - 6.3.2.3/2 "Conversions - Pointers").
However, if you go from 2 to 1, then the API changes because a pointer to a const object cannot be implicitly converted to a pointer to a non-const object. The following code would compile under version 2, but would not compile under version 1:
static const mystruct foo;
f(&foo);
Other than stated in the two previous answers going from 1->2 may or may not break the API. This depends on the base type mystruct
. The API would break if other than what the name indicates mystruct
would be a typedef
to an array type.
typedef struct toto mystruct[1];
For such a beast
mystruct A;
f(&A);
the call to f
would be valid before the API change but invalid afterwards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With