L
Levent
Hi,
When compiled with gcc 3.3.3 and lower on various systems (tried cygwin,
linux, aix) the following code behaves strangely:
#include <iostream>
class Foo {
public:
typedef int subs[3];
void callme(subs s)
{
std::cout << s[2] << std::endl;
}
};
template<class foo_type>
class Bar
{
public:
void callme(typename foo_type::subs s)
{
std::cout << s[2] << std::endl;
}
};
int main()
{
int sz[]={10,20,30};
Foo f;
f.callme(sz); // should print 30 and it does
Bar<Foo> b;
b.callme(sz); // should print 30 but it does not with gcc
return 0;
}
The problem is that `Bar<Foo>::callme' somehow accesses uninitized space
in memory instead of the one sz[] points to. This is not the case with
any other compiler I had access to (visual c++ 7.1, visualage 6, intel
7 and 8).
Does the above code have semantic problems, or is this just a gcc-bug
(in which case I apologize for this gcc specific and thus off-topic(ish)
thread)?
- L.
When compiled with gcc 3.3.3 and lower on various systems (tried cygwin,
linux, aix) the following code behaves strangely:
#include <iostream>
class Foo {
public:
typedef int subs[3];
void callme(subs s)
{
std::cout << s[2] << std::endl;
}
};
template<class foo_type>
class Bar
{
public:
void callme(typename foo_type::subs s)
{
std::cout << s[2] << std::endl;
}
};
int main()
{
int sz[]={10,20,30};
Foo f;
f.callme(sz); // should print 30 and it does
Bar<Foo> b;
b.callme(sz); // should print 30 but it does not with gcc
return 0;
}
The problem is that `Bar<Foo>::callme' somehow accesses uninitized space
in memory instead of the one sz[] points to. This is not the case with
any other compiler I had access to (visual c++ 7.1, visualage 6, intel
7 and 8).
Does the above code have semantic problems, or is this just a gcc-bug
(in which case I apologize for this gcc specific and thus off-topic(ish)
thread)?
- L.