#include "stdio.h"
double golbal = 3.14; // global data
static double local = 2.718; // local data
double fun() // global function
{
return 1.0;
}
static double lfun() // local function
{
return 2.0;
}
int main()
{
printf("Hello World!\n");
return 0;
}
Then I compile it with gcc and g++ into object files. Using the nm command I look look into the object and here is what I got.
With gcc
0000000000000000 T fun
0000000000000000 D golbal
0000000000000019 t lfun
0000000000000008 d local
0000000000000032 T main
U puts
With g++
0000000000000000 T _Z3funv
U __gxx_personality_v0
0000000000000000 D golbal
000000000000001a T main
U puts
As you can see g++ mangles names. Also the printf call becomes puts and is an undefined symbols. Now the local data and function our shown in the gcc object while not in the g++ object. The other thing is the g++ object has a symbol of the name __gxx_personality_v0. Now I don't claim to explain all this or understand it, but there it is. If you man nm you can get more information on what all time means. There are other command like objdump that tell more and many more options to nm.
Someday I hope to understand all this.
1 comment:
What is nm short for? I can see what it does at about.com but it doesn't exactly say what the abbreviation is.
Post a Comment