Solved

Need explanation on Symbol table

Posted on 2007-03-29
5
699 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 13

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now