OLD: void f(mystruct *a) NEW: void f(const mystruct *a)
ABI: If a was an out parameter, then old applications may be corrupted.
API: It seems to be compatible.
OLD: void f(const mystruct *a) NEW: void f(mystruct *a)
ABI: The function f may try to change the value of a parameter that should not be changed by old applications.
API: Compiler Error.
EDIT (1): This is an example showing a compiler error than changing a non-constant parameter:
library header.h:
struct mystruct { int f; }; void f(struct mystruct *a);
Application:
int main() { const struct mystruct x = {1}; f(&x); return 0; }
compiler error ( gcc -Werror app.c ):
error: passing argument 1 of 'f' discards qualifiers from pointer target type note: expected 'struct mystruct *' but argument is of type 'const struct mystruct *'
This is really a warning in C by default, but a bug in C ++. This way you will break C-based applications compiled with the -Werror option and C ++-based applications compiled using g ++.
aponomarenko
source share