 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
ChrisG Guest
|
Posted: Tue Nov 29, 2005 3:29 am Post subject: problem with default constructor of global object |
|
|
Hi,
I have a simple code:
==================================================
#include <iostream.h>
class InstructionSet
{
public:
InstructionSet() {
cerr << "InstructionSet CONSTRUCTORn";
}
~InstructionSet() {
cerr << "InstructionSet DESTROYEDn";
}
};
InstructionSet globalInstructionSet;
int main(int argc, char * argv[])
{
cerr << "mainn";
return 0;
}
==================================================
When I built and ran this on IBM AIX with xlc version 5, I got
main
But on the other UNIX platforms (HP, SGI, Alpha, Linux, SUN), I got
InstructionSet CONSTRUCTOR
main
InstructionSet DESTROYED
Do you know why the Aix build is not calling the default constructor?
The build commands on Aix are
Compiling rdc.cpp
xlc -q64 -O2 -DAIX5 -DRS64 -DRS6000 -qnolm -DUSE_AIX_LOCAL -c
-o rdc.o rdc.cpp -I. -Iunix -I../../include/
Creating rdc
xlc -q64 -O2 -DAIX5 -DRS64 -DRS6000 -qnolm -DUSE_AIX_LOCAL -o
rdc rdc.o -bh:4 -bpT:0x10000000 -bpD:0x200000 -L. -L../../bin/ -lbsd
-q64 -lpthreads -lC -lC -lc -lxlf90 -lm
Many thanks in advance,
Chris
|
|
| Back to top |
|
 |
Thomas Tutone Guest
|
Posted: Tue Nov 29, 2005 4:44 am Post subject: Re: problem with default constructor of global object |
|
|
ChrisG wrote:
| Quote: | I have a simple code:
==================================================
#include
class InstructionSet
{
public:
InstructionSet() {
cerr << "InstructionSet CONSTRUCTORn";
}
~InstructionSet() {
cerr << "InstructionSet DESTROYEDn";
}
};
InstructionSet globalInstructionSet;
int main(int argc, char * argv[])
{
cerr << "mainn";
return 0;
}
==================================================
When I built and ran this on IBM AIX with xlc version 5, I got
main
But on the other UNIX platforms (HP, SGI, Alpha, Linux, SUN), I got
InstructionSet CONSTRUCTOR
main
InstructionSet DESTROYED
Do you know why the Aix build is not calling the default constructor?
The build commands on Aix are
Compiling rdc.cpp
xlc -q64 -O2 -DAIX5 -DRS64 -DRS6000 -qnolm -DUSE_AIX_LOCAL -c
-o rdc.o rdc.cpp -I. -Iunix -I../../include/
Creating rdc
xlc -q64 -O2 -DAIX5 -DRS64 -DRS6000 -qnolm -DUSE_AIX_LOCAL -o
rdc rdc.o -bh:4 -bpT:0x10000000 -bpD:0x200000 -L. -L../../bin/ -lbsd
-q64 -lpthreads -lC -lC -lc -lxlf90 -lm
|
Since you never actually use globalInstructionSet, it may be that it's
simply being optimized out of existence. Try recompiling without
optimizations and see if you still have that problem.
Best regards,
Tom
|
|
| Back to top |
|
 |
Axter Guest
|
Posted: Tue Nov 29, 2005 7:47 am Post subject: Re: problem with default constructor of global object |
|
|
ChrisG wrote:
| Quote: | Hi,
I have a simple code:
==================================================
#include <iostream.h
class InstructionSet
{
public:
InstructionSet() {
cerr << "InstructionSet CONSTRUCTORn";
}
~InstructionSet() {
cerr << "InstructionSet DESTROYEDn";
}
};
InstructionSet globalInstructionSet;
int main(int argc, char * argv[])
{
cerr << "mainn";
return 0;
}
==================================================
When I built and ran this on IBM AIX with xlc version 5, I got
main
But on the other UNIX platforms (HP, SGI, Alpha, Linux, SUN), I got
InstructionSet CONSTRUCTOR
main
InstructionSet DESTROYED
Do you know why the Aix build is not calling the default constructor?
The build commands on Aix are
Compiling rdc.cpp
xlc -q64 -O2 -DAIX5 -DRS64 -DRS6000 -qnolm -DUSE_AIX_LOCAL -c
-o rdc.o rdc.cpp -I. -Iunix -I../../include/
Creating rdc
xlc -q64 -O2 -DAIX5 -DRS64 -DRS6000 -qnolm -DUSE_AIX_LOCAL -o
rdc rdc.o -bh:4 -bpT:0x10000000 -bpD:0x200000 -L. -L../../bin/ -lbsd
-q64 -lpthreads -lC -lC -lc -lxlf90 -lm
iostream.h> is not part of the C++ standard, and therefore not |
portable.
You should use <iostream> instead, which is part of the standard and
portable.
Some implementations keep legacy code in their <iostream.h> version
which also includes bugs they don't fix, because they're no longer
updating the non-standard headers.
For more reliable code, and for more portability, you should always use
the extensionless STL header <iostream>
|
|
| Back to top |
|
 |
ChrisG Guest
|
Posted: Tue Nov 29, 2005 7:09 pm Post subject: Re: problem with default constructor of global object |
|
|
Thanks for the suggestions.
Using xlC instead of xlc solved the problem.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|