[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]


    Search the Q&A Archives


...prototype and Macros in C ?

<< Back to: comp.lang.c Answers to Frequently Asked Questions (FAQ List)

Question by Harsha
Submitted on 9/19/2003
Related FAQ: comp.lang.c Answers to Frequently Asked Questions (FAQ List)
Rating: Rate this question: Vote
What is prototype and Macros in C ?



Answer by CHARAN
Submitted on 2/23/2004
Rating:  Rate this answer: Vote
HI GUYS
WHAT IS HYPO CHECKING???
Macros and function are related in what aspect?

 

Answer by hisham.s.a
Submitted on 3/22/2004
Rating:  Rate this answer: Vote
macros are preprocessors and prototypes are
the definition of a function it is also one kind of preprocessor

 

Answer by tjnomad
Submitted on 9/27/2004
Rating: Not yet rated Rate this answer: Vote
macros are pre-process before compile and  expanded for the 'C' compiler to operate on and understand.

 

Answer by rg
Submitted on 10/1/2004
Rating: Not yet rated Rate this answer: Vote
i do agree

 

Answer by Harish Kamalapurkar
Submitted on 11/9/2004
Rating: Not yet rated Rate this answer: Vote
Prototype :

Normally function prototypes are declared at the beginning of the main function. The only advantage of writting a prototype is that the compiler can catch the discrepancy if any during the compile time itself.

for eg.
if i write a prototype as
void fun (int);
in my main programe if i am writting a statement like

{
double a;
fun (a);
}
The compiler knows that this is an error and it will flash an error during the compilation itself. So prototypes are mearly ment for the compiler i.e you are telling the compiler about the return value and the type of arguments for the function.


MACROS:
These are handelled by the preprocessor. Preprocessing is the first step which takes place before compilation. There are several advantages of using macros. They improve the readability, portability and documentability.
#define MACRO replacement text

This macro will just replace the tag with the replacement text wherever the tag appears in the source file. The important thing for macros is that they dont follow scope rules i.e they can be declared at any place, inside the block, outside the block. The effect starts from the place it is declared.

 

Answer by sarada
Submitted on 3/22/2005
Rating: Not yet rated Rate this answer: Vote
macros are the preprocessors
and prototypes are the declarations for
functions to be defined later.

 

Answer by gk
Submitted on 4/11/2005
Rating: Not yet rated Rate this answer: Vote
Macros are similar to functions but have different functionality. When a macro is used, the code is just substituted..
for example
#define sum(e,f) (e+f)
main()
{
int r=9,t=8;
sum(r,t);
}
The macro sum(r,t) will be substituted by the statement (r+t).
This is not the case with function.. The function call will be executed and will not substituted. when used frequently, macros slows down compilation, but is effective when used with simpler logic.
Prototype is to tell the compiler that this function is defined else where after the function call. When a function call appears before its definition, prototype is must or else it give error.
If u have further doubt, feel free to post the ques

 

Answer by dhanus
Submitted on 11/1/2005
Rating: Not yet rated Rate this answer: Vote
what is a null macro?what is the difference between null pointer and null macro

 

Answer by rafi
Submitted on 5/15/2006
Rating: Not yet rated Rate this answer: Vote
Macro is combination of one or more statements or instructions to carry out particular task automatically when invoked.

 

Answer by harioum
Submitted on 6/2/2006
Rating: Not yet rated Rate this answer: Vote
macro is specially a preprocessor directives. this macro replaced by its function code before
the compilation of that function.
as
#define max 12
define function always strats with #
here we can replace max by 12 entire the program.

 

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.


Your name or nickname:
If you'd like to create a new account or access your existing account, put in your password here:
Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

 

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

 

<< Back to: comp.lang.c Answers to Frequently Asked Questions (FAQ List)


[ Home  |  FAQ-Related Q&As  |  General Q&As  |  Answered Questions ]

© 2008 FAQS.ORG. All rights reserved.