M
Milan Cvetkovic
Hi,
Recently I came accross a weird bug in my code which turned to be my
missunderstanding of arrays in C++. It all boils down to the small example:
template<class ITER>
const char* gggg (ITER value)
{
return value;
}
int main (int /*argc*/, char* /*argv*/[])
{
const char array[] = "ABCD";
const char* p1 = gggg(array);
const char* p2 = gggg(array+0);
if (p1 == p2)
return 0;
else
return 1;
}
This program will report different results when compiled with different
compiler. In particular, g++-2.95.2 returns 1 (pointers are not equal)
and g++-4.1 returns 0 (pointers are equal).
Is this a compiler bug in 2.95.2, or the C++ spec allows the compiler do
this funny stuff.
Thanks, Milan.
Recently I came accross a weird bug in my code which turned to be my
missunderstanding of arrays in C++. It all boils down to the small example:
template<class ITER>
const char* gggg (ITER value)
{
return value;
}
int main (int /*argc*/, char* /*argv*/[])
{
const char array[] = "ABCD";
const char* p1 = gggg(array);
const char* p2 = gggg(array+0);
if (p1 == p2)
return 0;
else
return 1;
}
This program will report different results when compiled with different
compiler. In particular, g++-2.95.2 returns 1 (pointers are not equal)
and g++-4.1 returns 0 (pointers are equal).
Is this a compiler bug in 2.95.2, or the C++ spec allows the compiler do
this funny stuff.
Thanks, Milan.