cabiqualifiersstorage-class-specifier

Which C specifiers may cause ABI incompatibility between the caller and callee?


Suppose there is a file with a declaration of a function which differs from the actual definition in another file i.e.

FileA.c

short foo();

int main(){
   foo();
}

FileB.c

int foo(){
   //Some code
}

This is obviously wrong code but it illustrates what the topic is.

The problem is that a compiler will not produce a machine code that will reserve enough space for the return value of foo when it's called. I think this can be called ABI incompatibility.

There are multiple different specifiers one may apply to a function or variable i.e. type qualifiers, storage class specifiers, atomics etc. I wonder which of these could potentially cause any kind of incompatibilities between a caller and a callee. Consider the case that these files might be compiled to separate binaries but still call the function via a pointer to an address.


Solution

  • I wonder which of these could potentially cause any kind of incompatibilities between a caller and a callee"

    Simply assume any difference risks incompatibility.

    Some difference are OK, yet those are often implementation defined. There is little value in exploiting a difference that is compatibility.

    See also direct qualifiers.

    The best way to deal with declarations of extern declarations between translation units (TU) is to use the same header in both TUs.