Type safety could prevent nuclear war
tsbockman via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 4 15:21:54 PST 2016
On Thursday, 4 February 2016 at 23:10:23 UTC, H. S. Teoh wrote:
> On Thu, Feb 04, 2016 at 10:57:00PM +0000, tsbockman via
> Digitalmars-d wrote:
>> The annual Underhanded C Contest announced their winners today.
>>
>> As always, the results are very entertaining, and also an
>> excellent advertisement for languages-that-are-not-C.
>>
>> The first place entry is particularly ridiculous; is there any
>> modern language that would make it so easy to commit such an
>> awful "mistake"?
>>
>> http://www.underhanded-c.org/#winner
>>
>> Actually, I'm surprised that this works even in C - I would
>> have expected at least a compiler (or linker?) warning; this
>> seems like it should be easy to detect automatically.
>
> The C preprocessor accepts all sorts of nasty, nonsensical
> things.
Definitely. What puzzles me about the winning entry, though, is
that the compiler and/or linker should be able to trivially
detect the type mismatch *after* the preprocessor pass(es) are
already done.
It should just see that the post-preprocessor signatures of
`spectral_contrast()` in match.c and spectral_contrast.c are in
conflict, and either issue a warning, or refuse to link them at
all.
More information about the Digitalmars-d
mailing list