I need a portable way to create an array of buffers.

I am trying to make a code portable between cxx,
Compaq/DEC'sAlpha C++ compiler, and gcc 2.8.1.

When I compile the following code with cxx,
it seg faults on the line "FileBufs[i] = new Tuple[ 1000 ] "

gcc handles this without seg faulting.

The #ifdef  __DECCXX_VER
is true on cxx and false on gcc.  I had
to add this #ifdef because cxx objects to
"Tuple **FileBufs = new (Tuple*)[ 64 ] ;"

giving the following error message:

cxx: Error: createTupleBogus.cc, line 11: a value of type "Tuple *" cannot be
          used to initialize an entity of type "Tuple **"
  Tuple **FileBufs = new (Tuple*)[ 64 ] ;
cxx: Info: 1 error detected in the compilation of "createTupleBogus.cc"

Without further ado, here is the complete listing
for createTupleBogus.cc:

typedef struct Tuple { long TupleVal; int ReadID; } Tuple ;

  int i;

#ifdef  __DECCXX_VER
  Tuple **FileBufs = new (Tuple**)[ 64 ] ;
  Tuple **FileBufs = new (Tuple*)[ 64 ] ;

  for (i=0; i < 64; i++ ) {
    FileBufs[i] = new Tuple[ 1000 ] ;


Any hints greatly appreciated as always.


Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

IexpertConnect With a Mentor Commented:
Don't use brackets, and only one *

Tuple** FileBufs = new Tuple*[64] ;
klopterAuthor Commented:
Well done.  My code now compiles and
executes under both g++ and cxx.

So, how did you know that would work?

Thanks again,
All Courses

From novice to tech pro — start learning today.