Type safety could prevent nuclear war
Chris Wright via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 4 15:24:21 PST 2016
On Thu, 04 Feb 2016 22:57:00 +0000, tsbockman 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.
C linkage does zero name mangling, which is the problem. C++ introduced
name mangling, so compiling with g++ would show the error rather quickly.
C99 is pretty close to C++98, but there are enough differences that that
isn't a reliable diagnostic. (Though if you're familiar with the
differences, you could use it as a quick way to show potential problem
areas.)
I suppose a compiler could produce two symbol tables, one featuring
mangled names and one with unmangled names. The linker would prefer
matching mangled names and issue a warning if it only had an unmangled
match with a mangled false match.
More information about the Digitalmars-d
mailing list