problem with default constructor of global object

C

ChrisG

Hi,

I have a simple code:

==================================================
#include <iostream.h>

class InstructionSet
{
public:
InstructionSet() {
cerr << "InstructionSet CONSTRUCTOR\n";
}
~InstructionSet() {
cerr << "InstructionSet DESTROYED\n";
}
};

InstructionSet globalInstructionSet;

int main(int argc, char * argv[])
{
cerr << "main\n";
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
 
T

Thomas Tutone

ChrisG said:
I have a simple code:

==================================================
#include <iostream.h>

class InstructionSet
{
public:
InstructionSet() {
cerr << "InstructionSet CONSTRUCTOR\n";
}
~InstructionSet() {
cerr << "InstructionSet DESTROYED\n";
}
};

InstructionSet globalInstructionSet;

int main(int argc, char * argv[])
{
cerr << "main\n";
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
 
A

Axter

ChrisG said:
Hi,

I have a simple code:

==================================================
#include <iostream.h>

class InstructionSet
{
public:
InstructionSet() {
cerr << "InstructionSet CONSTRUCTOR\n";
}
~InstructionSet() {
cerr << "InstructionSet DESTROYED\n";
}
};

InstructionSet globalInstructionSet;

int main(int argc, char * argv[])
{
cerr << "main\n";
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top