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 ;


main(){
  int i;

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

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

}


Any hints greatly appreciated as always.

Ken

klopterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IexpertCommented:
Don't use brackets, and only one *

Tuple** FileBufs = new Tuple*[64] ;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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,
  Ken
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.