Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of references in 64bit environments

Tags:

c++

64-bit

Came across this one while browsing the response to another question on SO (References Vs Variable Gets). My question is that for all 64bit environments is it guaranteed that a reference to a variable will be of 64 bits even if the original had a lesser size? As in char references in 64bit environment would be >sizeof(char)? Is there any section in the standard which specifies this explicitly?

EDIT: For more clarity -- char c1 = 'a'; char& c2 = c1; My question is sizeof(c2) > sizeof(c1) in 64bit machines?

like image 746
Fanatic23 Avatar asked Sep 19 '10 05:09

Fanatic23


1 Answers

The Standard (ISO C++-03) says the following thing about references

It is unspecified whether or not a reference requires storage (3.7).

Please someone correct me if I am wrong or if I have not understood his question correctly.

EDIT:

My question is sizeof(c2) > sizeof(c1) in 64bit machines?

No, as @Chubsdad noticed sizeof(c2) = sizeof (c1), the relevant quote from the Standard is

When applied to a reference or a reference type, the result is the size of the referenced type. (ISO C++ $5.3.3/2)

like image 180
Prasoon Saurav Avatar answered Oct 17 '22 10:10

Prasoon Saurav