Porting to g++ from MS VC++ - question
David Suna
eds@2amdev.co.il
Fri Oct 1 00:00:00 GMT 1999
I sent this out once before and didn't get any responses. I am not sure if it
made it out so I am trying again.
I am porting an application from Microsoft VC++ to Linux using g++ (egcs-1.1.2
release). Under VC if you have a class defined with no virtual functions the
compiler optimizes the vtable out of the class. This is not happening under
g++. Is there a way to have g++ do this as well?
The code below illustrates what is happening. When I compile under Windows I
get the output
sizeof i = 8
sizeof j = 8
When I compile the same code under Red Hat Linux 6 I get
sizeof i = 12
sizeof j = 8
Here is the code:
#include <stdio.h>
class test_class
{
public:
void print_test(void) { printf("TEST\n"); }
};
main()
{
struct I : public test_class {
int j[2];
};
I i;
struct J
{
int k[2];
};
J j;
printf("sizeof i = %d\n", sizeof(i));
printf("sizeof j = %d\n", sizeof(j));
}
There are numerous assumptions made in the code that I am porting that depend
on the size of structures. The client will be running on Windows and the
server will be running on Unix. The structures are written over the
network using sizeof. Thus it is not simply a matter of recompiling to get the
behavior desired.
Any help would be appreciated.
David Suna
eds@2am.com
More information about the Gcc-help
mailing list