This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Help with linking and symbol resolution
- From: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- To: Lakshay Garg <lakshaygarg1996+gcc at gmail dot com>, Andrew Haley <aph at redhat dot com>
- Cc: ryxi at stu dot xidian dot edu dot cn, gcc-help at gcc dot gnu dot org
- Date: Sun, 29 Jan 2017 13:52:22 +0800
- Subject: Re: Help with linking and symbol resolution
- Authentication-results: sourceware.org; auth=none
- References: <CAJq3jyziSS4ScBbz5b8szCyAdFHnUfkL0f=BxgZggQHyzzhgYw@mail.gmail.com> <f323cab3-c8be-5534-b45a-f77e06d3d673@redhat.com> <CAJq3jyyJWN34OcSh91xHeew5ptbJtHZj-VGWAGiia1URT7g59w@mail.gmail.com>
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