View Single Post
  #2 (permalink)  
Old July 5th, 2006, 07:43 AM
S1v S1v is offline
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by imroostercogburn
 For preprocessor directives is the Preprocessor application part of the Compiler or is it separate. Does the compiler first run the preprocessor application and then continues to compile??

Preprocessor directivea, as name suggests are "instructions" that you give to the COMPILER. The compiler first parses these directives and usually substitutes them with its own code. for e.g...

Code:
#include <stdio.h> /*indicates to your the compiler that you are going
 to use function defines in stdio header file. Without which, if the
 printf function is used would lead to an error since printf is
declared only in this header file*/
#define MAX(A,B) ((A)>(B)?(A):(B))

int main(void)
{
  printf("Hello, World!\r\n");
  printf("Max is %d",MAX(10,20));
  /*The above line will become
    printf("Max is %d",((10)>(20)?(10):(20)));
    just befor compilation*/

  return 0;
}
Quote:
quote:when you execute a C program is it the OS that calls the main() function. In Java its the JVM but is it the OS in C?
You are correct. It is the OS that calls the main funtion from its shell; which is why in general it is said that a program quits when "main() returns". The proper format for the main() function is ALWAYS
Code:
int main(int argc, char** argv)
Your program must ALWAYS return a status code back to the OS. Usually is is
0 (or) EXIT_SUCCESS for normal termination and
error-code (or) EXIT_FAILURE for an abnormal termination

Never use void main()... since it only reflects bad programming on the part of a developer.


Reply With Quote