Topic: Which is correct behavior?


Author: fst@nimo.claircom.com (Fariborz Skip Tavakkolian)
Date: Sat, 7 Aug 1993 22:48:41 GMT
Raw View

Are the array semantics in C++ identical to those of C, including user
defined types?

The following program compiles and executes correctly with g++
(2.3.2); but when compiling with cfront (SUN SPARC, Release
version SC2.0.1), cfront gives following error:

   "bar.C", line 21: error: address of  numeric constant
   Compilation failed

/////////////////////////////////////////////////////////////////////
#include <iostream.h>
#include <stdio.h>
#include <osfcn.h>

struct X
{
friend ostream& operator<<(ostream&, const X&);
  int x;
  X() : x(0)  {}
  ~X()   {}
  X& operator=(int i) { return x = i, *this; }
};

ostream& operator<<(ostream& o, const X& xxx)
{
  o << xxx.x;
  return o;
}

main()
{
  X xx[4];
  xx[0] = 1, xx[1] = 2, xx[2] = 3, xx[3] = 4;
  cout << (0["UNIX"]) << endl;
  cout << (0[xx]) << endl;  // line 21
}
/////////////////////////////////////////////////////////////////////


Thanks
Skip
--
    ********************************************************************
    *  Fariborz ``Skip'' Tavakkolian Claircom Communications Group  *
    *  fst@claircom.com   700 Fifth Ave, Suite 2100      *
    *  (206)389-7150   Seattle, WA.  98104            *
    ********************************************************************