sizeof returns wrong value
Bob Sidebotham
rns@fore.com
Thu Jan 8 09:48:00 GMT 1998
In egcs-1.0 on both Linux and SunOS platforms, I get the following
inconsistency with sizeof. In two invocations of a constructor, passed
the identical array, the sizeof function returns two different values.
The only difference is that in the first instance, the constructor is
called during the creation of a temporary, and in the second instance
it is called to create a variable on the stack.
This is the smallest example I was able to come up with.
#include <iostream.h>
class choice {
public:
template<class C> choice(const C& choices) {
cout << sizeof(choices) << endl;
}
void noop() {};
};
main() {
const char* list[] = { "foo", "bar", "baz" };
choice(list).noop();
choice foo(list);
}
On both platforms, the output is:
4
12
The correct output would be:
12
12
More information about the Gcc-bugs
mailing list