▲ | AlotOfReading 3 days ago | |
The ABI thing is because Lisa's talk was about C++. In C, a function can have multiple declarations as long as they're compatible (as opposed to identical). So these declarations might coexist without issue even though they have different signatures:
whereas this would be incompatible
If you attach things to the prototype, then you need to sort out the compatibility rules. If contract_assume(a > 0) changes the type, the extern shouldn't be compatible. This is frequently used to allow linking against libraries compatible with older language standards while allowing newer code to benefit from newer standards like C99, C11, or C23.The C23 committee ran into this issue when introducing attributes. Their solution was just exclude attributes from the signature and say they're always compatible:
| ||
▲ | 1718627440 3 days ago | parent [-] | |
Maybe I'm missing something, but how does this change anything to how it's now? I can happily declare two completely incompatible functions with the same symbol name, as long as they are in separate TUs and I don't use -flto, neither the compiler nor the linker will complain and my program will simply be garbage. This won't change with incompatible contracts. When I both show them to the compiler, when they contradict, the compiler will complain, that also doesn't change. Of course this will not work:
However this will:
But this isn't a problem, since this is precisely the feature we want to introduce contracts for: catching function call mismatches that are not yet expressible in the language.> while allowing newer code to benefit from newer standards Having no contract specified should of course result in no additional restrictions being exposed beside this already present now. This wouldn't be possible:
But I don't think anybody is arguing for that. |