Topic: Dynamic reference initialization
Author: Friedbert Widmann <widi@uni-koblenz.de>
Date: 1998/01/19 Raw View
Is the following code correct?
int a = 3;
extern const int& b;
const int c = b; // (a)
const int& b = a; // (b)
int main() {}
This program works on the most systems. But one compiler
generate code for a dynamic initialization of the reference
in line (b). This results in an exception in line (a), because
'b' isn't initialized at that point --- 'b' is a 'null-reference'.
My question: What is ill-formed? My program or the compiler?
I found a few notes in the C++-standard paper:
8.5.7: 'a reference is bound directly'
Without any initialzation?
8.3.2: 'a null reference cannot exist in a well-defined program'
But the generated code contains a null reference.
Please help!
Widi
--
Friedbert Widmann phone: +49-261-38410
Friedrich-Ebert-Ring 44 eMail: widi@uni-koblenz.de
56068 Koblenz WWW: http://www.uni-koblenz.de/~widi
---
[ 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
]