Topic: Type conflicts
Author: erikoest@idt.unit.no (Erik Oestlyngen)
Date: 1996/02/23 Raw View
Hi.
I'm doing working with a project trying to make a model for namespace
structure of C++ programs, and make a visualization of it. (by the
way, does anyone know of any interesting stuff on the net in this
context ?)
Anyhow, i've got this little problem:
When i define two different structs with the same name in two
different files, my compiler don't complain. I can then use the struct
as input parameter for a function in one file, and from the other send
the different struct into the function. The function will then get
an other input type than it expects.
What does the ansi-C++ standard say about this?
Example:
========
File1:
struct a {
int x;
};
extern void f(struct a);
void main(void)
{
struct a str;
str.x=1;
f(str);
}
---------------------
File2:
struct a {
long x;
};
void f(struct a astr)
{
astr.x+=2; // crash, bang, crunch
}
--
--Erik Oestlyngen
---------------------------------------------------------------
erikoest@idt.unit.no URL http://www.idt.unit.no/~erikoest/
[ To submit articles: Try just posting with your newsreader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]