Re: Help with linking and symbol resolution

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28/01/17 11:35, Lakshay Garg wrote:
> /* f1.c */
> #include <stdio.h>
> 
> double c;
> int main() {
>   c = 1;
>   printf("sizeof(c) = %lu\n", sizeof(c));
>   return 0;
> }
> 
> /* f2.c */
> int c = 0;
> 
> I compile the program using gcc f1.c f2.c. From what I have learnt, I
> believe that the output of the file should be sizeof(c) = 4 since the
> declaration of c in f1.c is weak and would be resolved to the symbol c
> in file f2.c which is strong. 

I do this:

 $ gcc f1.c f2.c -Wall
/usr/local/bin/ld: Warning: alignment 4 of symbol `c' in f2.o is smaller than 8 in f1.o
/usr/local/bin/ld: Warning: size of symbol `c' changed from 8 in f1.o to 4 in f2.o

You should always use -Wall when gcc does anything unexpected.

Hint: make sure you declare the type of c in every source file.  Feel free
to use a header file to do this.

Andrew.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux