在浏览SO上的另一个问题的响应时遇到了这个(References Vs Variable Gets).我的问题是,对于所有64位环境,即使原始版本的尺寸较小,它也能保证对变量的引用为64位吗?在64位环境中的char引用中将是> sizeof(char)?标准中是否有明确规定的部分?
编辑:为了更清晰 - char c1 ='a'; char&c2 = c1; 我的问题是64位机器中的sizeof(c2)> sizeof(c1)?
Pra*_*rav 13
标准(ISO C++ - 03)说明了关于参考文献的内容
It is unspecified whether or not a reference requires storage (3.7).
如果我错了或者我没有正确理解他的问题,请有人纠正我.
编辑:
我的问题是64位机器中的sizeof(c2)> sizeof(c1)?
不,正如@Chubsdad注意到的那样sizeof(c2) = sizeof (c1),标准的相关引用是
When applied to a reference or a reference type, the result is the size of the referenced type.(ISO C++ $ 5.3.3/2)
$ 8.3.2/3 - It is unspecified whether or not a reference requires storage.
应用于引用的sizeof基本上是引用的大小.
因此,如果'r'是对'i'的整数引用,则如果存在'r'的实际存储,则未指定.但sizeof(r)内部代表sizeof(i).
如果'r'是对'char'的引用,sizeof(r)则将始终sizeof(char) == 1按定义.