New Reply

A few questions about C programming language...

 
Share Thread Thread Tools
Feb23-13, 02:49 PM   #1
 

A few questions about C programming language...


1. In what direction does a compiler read a program? Left to right, top to bottom?

2. What does it mean when a function is called by another. Like when main() is called by the operating system, what is going on within the computer? Does the OS send a code in binary or what?

3. When the compiler hits "return 0;" does the program stop executing completely? Or does it continue to read the program from a different point?

Thanks
 
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Heat-related deaths in Manhattan projected to rise
>> Dire outlook despite global warming 'pause': study
>> Sea level influenced tropical climate during the last ice age
Feb23-13, 03:42 PM   #2
 
Recognitions:
Homework Helper Homework Help
Quote by lundyjb View Post
1. In what direction does a compiler read a program? Left to right, top to bottom?
It reads the source code top to bottom, then each line left to right. The order of execution of operators depends on precedence and parenthesis (if present).

Quote by lundyjb View Post
What does it mean when a function is called by another. Like when main() is called by the operating system, what is going on within the computer? Does the OS send a code in binary or what?
For a stacked based evironment, parameters are pushed onto the stack, then a "call" is made, which pushes the return address onto the stack, and a branch is made to the function.

Quote by lundyjb View Post
When the compiler hits "return 0;" does the program stop executing completely?
There is some code linked with a program that is not generated from the programmer's source code. This code calls main, passing the command line parameters (int argc, char **argv). When main returns, that code then returns to the system, via a system call, which is an usually X86 interrupt instruction (INT hex 21 with AH register = hex 4C) in the case of MSDOS or Windows. The return value from main is passed back to the operating system as an "exit code".
 
Feb26-13, 11:49 AM   #3
 
I have the feeling the 3rd question may have been even more basic than rcgldr's interpretation of it:

1) The compiler does not stop upon encountering a return statement. It will just continue compiling until the whole code is compiled or errors are encountered.

2) The running program, when encountering a "return 0;" statement (more precisely: the code generated from the statement), will leave the current function and return zero to the function that called it. In that sense the program does indeed continue at a different point, afterwards.

3) In the case that the current function is "main", which itself is not called from another function, this implies that the program ends.
 
Feb26-13, 01:11 PM   #4
 
Admin

A few questions about C programming language...


Quote by lundyjb View Post
1. In what direction does a compiler read a program? Left to right, top to bottom?
I would say - neither. It follows the information as it is ordered in a text file, character by character. We tend to represent it top-down, left-right, but it is just a matter of our convention, compiler doesn't care about the way we display the information.
 
New Reply
Thread Tools


Similar Threads for: A few questions about C programming language...
Thread Forum Replies
Best programming language? Academic Guidance 22
Which programming language is best? Academic Guidance 12
Recommended programming language (and texts) for middle-school beginner programming Programming & Comp Sci 9
Programming language Programming & Comp Sci 10
Which programming language do you use? Academic Guidance 20