Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do these members have unspecified ordering?

Tags:

c++

c++11

c++03

A colleague told me that, in the following type, all members have unspecified ordering in memory (relative to one another).

I doubt this, because they all have the same access level.

Who is correct?

struct foo { public: int x; public: int y; public: int z; }; 
like image 756
Lightness Races in Orbit Avatar asked Apr 02 '13 11:04

Lightness Races in Orbit


People also ask

What is the purchase order process?

The purchase order process consists of all the steps businesses take to create, approve, validate, manage, and track POs, from the moment a need is identified up to the point of delivery or sale.

WHO issues a purchase order?

The shop owner creates a purchase order laying out exactly what they need from the supplier. If the supplier has the inventory to fill the order, they'll accept the purchase order, fulfill it, and deliver the items on the agreed due date. The supplier will then send a bill or sales invoice for the purchased items.


1 Answers

Your colleague is correct for C++03:

[C++03: 9.2/12]: Nonstatic data members of a (non-union) class declared without an intervening access-specifier are allocated so that later members have higher addresses within a class object. The order of allocation of nonstatic data members separated by an access-specifier is unspecified (11.1). [..]

But you are correct for C++11:

[C++11: 9.2/14]: Nonstatic data members of a (non-union) class with the same access control (Clause 11) are allocated so that later members have higher addresses within a class object. The order of allocation of non-static data members with different access control is unspecified (11). [..]

(Spot the difference.)

like image 141
Lightness Races in Orbit Avatar answered Sep 23 '22 07:09

Lightness Races in Orbit