views:

70

answers:

2

Suppose you have this pseudo-code

do_something();

function do_something(){
   print "I am saying hello.";
}

Why do some programming languages require the call to do_something() to appear below the function declaration in order for the code to run?

+7  A: 

Programming languages use a symbol table to hold the various classes, functions, etc. that are used in the source code. Some languages compile in a single pass, whereby the symbols are pulled out of the symbol table as soon as they are used. Others use two passes, where the first pass is used to populate the table, and then the second is used to find the entries.

Ignacio Vazquez-Abrams
That's really not a feature of the language, but a specific property of the compiler you're using. Right?
jleedev
@jleedev: the language specification informs the compiler. Requiring names be declared before use allows for a one-pass compiler.
outis
+2  A: 
Norman Ramsey