Differences between Functio & Macro in C

U

uma676

Hi all,
I want to know the differebces between function and macro in c
language. if anybody can tell me atleast 4 diff's. for which i will
be regrated.

Rgds,
Balaji
 
R

Rouben Rostamian

I want to know the differebces between function and macro in c
language. if anybody can tell me atleast 4 diff's. for which i will
be regrated.

Why "at least 4"?

Without further explanation this sounds like a homework problem.
 
K

Kenny McCormack

I wouldn't want to be the cause of your being regrated. That sounds like
it would hurt.
Why "at least 4"?

Without further explanation this sounds like a homework problem.

Gee, ya think?
 
C

CBFalconer

Kenny said:
I wouldn't want to be the cause of your being regrated. That
sounds like it would hurt.

What a cheesy thing to say. :)

--
"I'm a war president. I make decisions here in the Oval Office
in foreign policy matters with war on my mind." - GWB 2004-2-8
"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02
"This notion that the United States is getting ready to attack
Iran is simply ridiculous. And having said that, all options
are on the table." - George W. Bush, Brussels, 2005-02-22
 
S

Suman

Netocrat wrote:
[snipped...]
Come on everyone, stop milking the jokes.
Ok, so here's my $0.02 - atleast for functions there's no naming
problem
when the name starts with uppercase E but for macros - remember the
big, green, ...(thanks goes to Chris Torek & Stan Milam for taking this
up at some other thread :) ).
 
F

Flash Gordon

Suman said:
Netocrat wrote:
[snipped...]
Come on everyone, stop milking the jokes.

Ok, so here's my $0.02 - atleast for functions there's no naming
problem
when the name starts with uppercase E but for macros - remember the
big, green, ...(thanks goes to Chris Torek & Stan Milam for taking this
up at some other thread :) ).

Except that if errno.h includes:
#define EBYGUM 666

If you then try:
#include <errno.h>
void EBYGUM(void)
{
}

The function definition will be expanded to:
void 666(void)
{
}

Which is obviously invalid.

So you've got to avoid names reserved for macros in your function names,
variable names, struct names etc (deliberately incomplete list)
 
R

Robert Maas, see http://tinyurl.com/uh3t

From: Clark S. Cox III said:
Wow, this thread has gone whey off topic.

We've had the Kurds and the whey,
we need a spider to scare the joke away!
(We already scared the student away, I hope!)
 
J

jdallen2000

CBFalconer said:
"If I knew then what I know today, I would still have invaded
Iraq. It was the right decision" - G.W. Bush, 2004-08-02

Thanks, Chuck; it's good to see someone appreciates
our Dear Leader. And last night we learned that it
was *still* the right decision.

Perhaps you should add another recent quote from the
Greatest American of the 21st century: "I think about
Iraq every day, every day!"

Think about it! Even on Saturdays and Sundays, he thinks
about Iraq. He was too modest to admit it, but I'm sure
some days he thinks about Iraq 2 or 3 times.

(And he's a busy man: I read in an Atlantic Monthly article
that before the war, the representative of several NGO's
was denied a meeting about humanitarian planning, because
"the President had already spent 20 minutes on that.")

"Our God is bigger than their God." Go Yanks!

James
 
D

Dienekes

uma676 said:
Hi all,
I want to know the differebces between function and macro in c
language. if anybody can tell me atleast 4 diff's. for which i will
be regrated.

Rgds,
Balaji

The main difference you want to know about macros vs functions is:

When you call a function your compiler enters a call-sequence (which takes
time) and allocates a new stack frame for that function (whcih takes text
stack space) so that the function's body can be executed. After it's done
you enter a returning-sequence phase (which takes time).

A macro does not need anything of the above, because it's preprocessor's job
to expand a macro, it's only about text replacement, not about compiler
stuff or code-generating issues. So you don't expend time and space doing
what a function would need in order to be executed.

That makes functions and macros completely different even if the result of
using both is, in some cases, the same. One must know it's suitable to use
one or the other. For instance: you can't point a pointer to a macro, but
you can use pointers to functions...

_______
Dienekes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Differences between C and C++ 100
macro prototype 5
Beginner at c 0
[C#] Extend main interface on child level 0
32/64 bit cc differences 110
C Macro define contain symbol # 19
MACRO help 23
C function macro question 5

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top