This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help with linking and symbol resolution


On 2017-01-28 20:40 +0530, Lakshay Garg wrote:
> Yes, I get this warning too. But what I want to understand is why do
> we get the size of c as 8 when it should be 4 because the linker will
> find that there are multiple declarations of c and will keep the
> strong one which is the declaration with int.

It's wrong. The C Standard (ISO/IEC 9899:1999 6.5.3.4) said:

  The sizeof operator yields the size (in bytes) of its operand, which
  may be an expression or the parenthesized name of a type. The size
  is determined from the type of the operand.

Here the operand of sizeof is the expression c. Its type is double. So
the result is absolutely sizeof(double). Linkage is irrevalent.
-- 
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]