Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would a reference be zero-initialized?

§8.5/6 in draft N3797 says:

To zero-initialize an object or reference of type T means:

  • ...
  • if T is a reference type, no initialization is performed.

I'd like to have an example of a reference that is zero-initialized.

like image 300
Alexander Avatar asked Jan 21 '14 16:01

Alexander


1 Answers

Later the standard says "Every object of static storage duration is zero-initialized at program startup before any other initialization takes place." So if you have e.g. in global scope

int x;
int& r = x;

r is first zero-initialized, and then initialized by x. For reference, zero-initialized means nothing, so it is mere technicality.

like image 102
Wojtek Surowka Avatar answered Oct 02 '22 19:10

Wojtek Surowka