Re: why this program is Crashing
On Jul 14, 3:59 pm, "Alf P. Steinbach" <al...@start.no> wrote:
* Pete Becker:
Juha Nieminen wrote:
Pete Becker wrote:
Pallav singh wrote:
extern int * arr;
ODR violation. file1.c says that arr is an array of 100 ints, and
file2.c says that it's a pointer to int. They are not the same type.
Shouldn't that cause a linker error?
ODR violations do not require diagnostics. Most compilation systems
don't check data types across modules.
This surprised me (the OP showed that he compiled as C; I
thought compilation as C++, with presumably mangled names,
would yield a linker error, but no).
It's stupid, but most C++ compilers only mangle function names.
Some sort of "extended" naming is necessary to support
overloaded functions. Since you can't overload data, it's not
strictly necessary for data. But it would certainly be an
advantage for the user. For that matter: why not mangle in an
MD5 hash of the definition of things that allow or require
multiple definitions, like classes, templates and inline
functions. A simple and easy way of catching one of the more
frequent causes of undefined behavior, maybe not 100% of the
time, but something like 99.9999%, which is still better than
James Kanze (GABI Software) email:email@example.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34