Solved

Need explanation on Symbol table

Posted on 2007-03-29
5
704 Views
Last Modified: 2012-06-27
Hi experts,

      Can anybody explain me the concept on symbol tables in detail with a small c program example?
I need the explation to address the following questions:
+ Why it is needed ? what is the use of it?

I know  I may be asking a silly question , but I need  an excellet answers from the experts.


Thanks

0
Comment
Question by:expertblr
5 Comments
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 18819280
Symbol tables have no real simple explanation.  

Say you're building a program.  Inside that program, you are assigning variables like 'x' or 'y'.  When you create the variable, the computer sets aside a section of memory for it (in the stack or heap...more terms!  yay!).  The amount of space reserved depends on the variable.  For example, a single character takes up one byte, integers take 4 (or more) bytes, etc.  The amount of space is OS-dependent as well; different systems use different data types.

So now you have variables 'x' and 'y'.  But the computer does not understand x or y...it understands 1's and 0's.  At this point, the computer knows what you're calling it, and it knows where it is holding the value.  It creates a table in memory to match the two - the symbol table.  Now every time you look up 'x', the computer goes to the symbol table and finds the address it gave to that variable, then goes to that address and returns the value you stored.  

Symbol tables are necessary as part of the translation from our language to the computer's.  As mentioned earlier, these are very OS-dependent and can vary widely in format, usage, and purpose.  In a compiler, the symbol table is created as a manifest for all declared variables.  As the compiler executes passes over the code it is compiling, it replaces plain-language variable references with the segment:offset pair for that variable's address.  In PHP, the symbol table is the global scope...just a place to hold variables.

I hope this explains well enough.  I have not dealt directly with symbol tables since assembler in 1984 or something, and I'm sure they have evolved tremendously over the years.
0
 
LVL 14

Expert Comment

by:kenfcamp
ID: 18819296
[I need the explation to address the following questions:
  Why it is needed ?
   what is the use of it?]


Sounds more like a home work assignment to me
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18819567
That it does, but I didn't need any code so....  :)  Understanding concept is what homework is all about.
0
 
LVL 84

Expert Comment

by:ozo
ID: 18820486
#include <stdio.h>
main(){
  int i=1;
  printf("%d\n",i);
}
the compiler need to know that the first i refers to the same variable as the second i
it also needs to know what printf is.
To keep track of these things, it uses a symbol table
0
 

Author Comment

by:expertblr
ID: 18882553
Thanks routinet.  I appricate  your help  without listening to others for whom it may look as an homework assignment.  Full pioints to you routinet.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ubuntu not booting - How get past GRUB? 3 41
Why isnt it sending mail from my php but is from my server 10 44
how to install java on RHEL image on EC2 4 26
number in printf 13 27
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question