Topic: const int assigned to int


Author: "Michel Joly de Lotbinihre" <mjdl@interlog.com>
Date: 1997/03/22
Raw View
For what it's worth, Watcom 11.0 gives:

ZERO  = 0
ONE   = 1
array1[0] = 0
array1[1] = 1
array2[0] = 0
array2[1] = 1
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: "Joe Halpin" <jhalpin@nortel.ca>
Date: 1997/03/17
Raw View
Is the following correct? If so, would someone explain why I get the
addresses of the const ints unless I cast them to plain int?

Thanks

#include <iostream.h>

extern const int ZERO  = 0;
extern const int ONE   = 1;

int array1[] = {ZERO,ONE};
int array2[] = {(int) ZERO, (int) ONE};

int main()
{
  cout << "ZERO  = " << ZERO  << '\n';
  cout << "ONE   = " << ONE   << '\n';

  cout << "array1[0] = " << array1[0] << '\n';
  cout << "array1[1] = " << array1[1] << '\n';

  cout << "array2[0] = " << array2[0] << '\n';
  cout << "array2[1] = " << array2[1] << '\n';
}

Output:

ZERO  = 0
ONE   = 1
array1[0] = 1073746524
array1[1] = 1073746520
array2[0] = 0
array2[1] = 1
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Marcelo Cantos <marcelo@mds.rmit.edu.au>
Date: 1997/03/17
Raw View
"Joe Halpin" <jhalpin@nortel.ca> writes:

> Is the following correct? If so, would someone explain why I get the
> addresses of the const ints unless I cast them to plain int?
>
> Output:
>
> ZERO  = 0
> ONE   = 1
> array1[0] = 1073746524
> array1[1] = 1073746520
> array2[0] = 0
> array2[1] = 1

Not on my compiler!  I think you might have a compiler bug.


--
______________________________________________________________________
Marcelo Cantos, Research Assistant      __/_   marcelo@mds.rmit.edu.au
Multimedia Database Systems Group, RMIT  /       _  Tel 61-3-9282-2497
723 Swanston St, Carlton VIC 3053    Aus/ralia ><_> Fax 61-3-9282-2490
Acknowledgements: errors - me; wisdom - God; funding - RMIT
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]