Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 2nd, 2006, 01:12 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default C Compiler question

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??

also, 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?

thanks for the help

Reply With Quote
  #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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiler Romaunt V. Intro Programming 2 October 18th, 2008 06:27 AM
"Compiler Options" Question (Newbie-Type) DaveLeeNC Access VBA 2 February 20th, 2006 08:09 AM
Siteheader won't get thru compiler wudwork BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 13th, 2005 05:59 PM
For all who need a C/C++ compiler... Ammiel C++ Programming 1 July 17th, 2003 01:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.