I've just read a book on Computer Systems.(Computer Systems:A programmer's perspective ) . On the part of "Linking" , the author talks about strong/weak symbol and as an example for the rule "Given a strong symbol and weak symbols , choose the strong one" , he gives the following C modules
Expand|Select|Wrap|Line Numbers
- /* foo5.c */
- #include<stdio.h>
- void f();
- int x=15213,y=15212;
- int main()
- {
- f();
- printf("%d %d",x,y);
- return 0;
- }
- /* bar5.c */
- double x;
- void f()
- {
- x=-0.0;
- }
So is it because the C++ compiler/linker is "smarter" ? So , what's the theories and rules added in c++ linker (if any ?)
One more question , I still dont understand this : if the symbol for x in foo5.c has been chosen , what causes y to be overwritten ? The author of the book said about int-4 byte and double-8 byte ,... But once x has been chosen as int , why double is concerned here ? I mean , why not the linker just throw away other definitions and treat x as int always from that time on ?
Replies appreciated ;