Differences between Functio & Macro in C

Discussion in 'C Programming' started by uma676, Jun 27, 2005.

  1. uma676

    uma676 Guest

    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
    uma676, Jun 27, 2005
    #1
    1. Advertising

  2. In article <d9p9r7$987$>,
    uma676 <-spam.invalid> wrote:
    >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.


    --
    Rouben Rostamian
    Rouben Rostamian, Jun 27, 2005
    #2
    1. Advertising

  3. In article <d9p9td$kh1$>,
    Rouben Rostamian <> wrote:
    >In article <d9p9r7$987$>,
    >uma676 <-spam.invalid> wrote:
    >>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.


    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?
    Kenny McCormack, Jun 27, 2005
    #3
  4. uma676

    CBFalconer Guest

    Kenny McCormack wrote:
    > Rouben Rostamian <> wrote:
    >> uma676 <-spam.invalid> wrote:

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

    >
    > 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
    CBFalconer, Jun 27, 2005
    #4
  5. On Mon, 27 Jun 2005 17:05:54 -0500, CBFalconer wrote
    (in article <>):

    > Kenny McCormack wrote:
    >> Rouben Rostamian <> wrote:
    >>> uma676 <-spam.invalid> wrote:

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

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

    >
    > What a cheesy thing to say. :)


    That's just full of holes.
    Lefty Bigfoot, Jun 28, 2005
    #5
  6. In article <>,
    Lefty Bigfoot <> wrote:
    >
    >On Mon, 27 Jun 2005 17:05:54 -0500, CBFalconer wrote
    >(in article <>):
    >
    >> Kenny McCormack wrote:
    >>> Rouben Rostamian <> wrote:
    >>>> uma676 <-spam.invalid> wrote:
    >>>
    >>>>> 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.
    >>>
    >>> I wouldn't want to be the cause of your being regrated. That
    >>> sounds like it would hurt.

    >>
    >> What a cheesy thing to say. :)

    >
    >That's just full of holes.


    They can't make jokes like that in Iraq, it upsets the Kurds.
    --
    7842++
    Anonymous 7843, Jun 28, 2005
    #6
  7. On 2005-06-27 21:58:16 -0400, (Anonymous 7843) said:

    > In article <>,
    > Lefty Bigfoot <> wrote:
    >>
    >> On Mon, 27 Jun 2005 17:05:54 -0500, CBFalconer wrote
    >> (in article <>):
    >>
    >>> Kenny McCormack wrote:
    >>>> Rouben Rostamian <> wrote:
    >>>>> uma676 <-spam.invalid> wrote:
    >>>>
    >>>>>> 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.
    >>>>
    >>>> I wouldn't want to be the cause of your being regrated. That
    >>>> sounds like it would hurt.
    >>>
    >>> What a cheesy thing to say. :)

    >>
    >> That's just full of holes.

    >
    > They can't make jokes like that in Iraq, it upsets the Kurds.


    Wow, this thread has gone whey off topic.

    --
    Clark S. Cox, III
    Clark S. Cox III, Jun 28, 2005
    #7
  8. uma676

    Netocrat Guest

    On Mon, 27 Jun 2005 22:27:27 -0400, Clark S. Cox III wrote:

    > On 2005-06-27 21:58:16 -0400, (Anonymous 7843) said:
    >
    >> In article <>, Lefty
    >> Bigfoot <> wrote:
    >>>
    >>> On Mon, 27 Jun 2005 17:05:54 -0500, CBFalconer wrote (in article
    >>> <>):
    >>>
    >>>> Kenny McCormack wrote:
    >>>>> Rouben Rostamian <> wrote:
    >>>>>> uma676 <-spam.invalid> wrote:
    >>>>>
    >>>>>>> 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.
    >>>>>
    >>>>> I wouldn't want to be the cause of your being regrated. That sounds
    >>>>> like it would hurt.
    >>>>
    >>>> What a cheesy thing to say. :)
    >>>
    >>> That's just full of holes.

    >>
    >> They can't make jokes like that in Iraq, it upsets the Kurds.

    >
    > Wow, this thread has gone whey off topic.


    Come on everyone, stop milking the jokes.
    Netocrat, Jun 28, 2005
    #8
  9. uma676

    Suman Guest

    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 :) ).
    Suman, Jun 28, 2005
    #9
  10. uma676

    Flash Gordon Guest

    Suman wrote:
    >
    > 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)
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
    Flash Gordon, Jun 28, 2005
    #10
  11. > From: Clark S. Cox III <>
    > >>> What a cheesy thing to say. :)
    > >> That's just full of holes.

    > > They can't make jokes like that in Iraq, it upsets the Kurds.

    > 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!)
    Robert Maas, see http://tinyurl.com/uh3t, Jun 28, 2005
    #11
  12. uma676

    CBFalconer Guest

    "Robert Maas, see http://tinyurl.com/uh3t" wrote:
    >> From: Clark S. Cox III <>
    >>
    >>>>> What a cheesy thing to say. :)
    >>>> That's just full of holes.
    >>> They can't make jokes like that in Iraq, it upsets the Kurds.

    >> 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!)


    Too late. The cannibalistic Miss Muffet has already eaten the
    Kurds and whey. Which is Tuff etting.

    --
    "A man who is right every time is not likely to do very much."
    -- Francis Crick, co-discover of DNA
    "There is nothing more amazing than stupidity in action."
    -- Thomas Matthews
    CBFalconer, Jun 29, 2005
    #12
  13. uma676

    Guest

    CBFalconer wrote:
    >
    > "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
    , Jun 29, 2005
    #13
  14. uma676

    Dienekes Guest

    "uma676" <-spam.invalid> escribió en el
    mensaje news:d9p9r7$987$...
    > 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
    Dienekes, Jul 6, 2005
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rex_chaos

    template functio need help

    Rex_chaos, Oct 1, 2003, in forum: C++
    Replies:
    7
    Views:
    429
    tom_usenet
    Oct 7, 2003
  2. Raghul

    Copy functio in imaplib

    Raghul, Feb 22, 2005, in forum: Python
    Replies:
    2
    Views:
    391
    Grant Edwards
    Feb 22, 2005
  3. Don Quijote de Nicaragua

    obtain value from functio + array

    Don Quijote de Nicaragua, Jul 27, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    279
    Don Quijote de Nicaragua
    Jul 27, 2008
  4. Home_Job_opportunity
    Replies:
    0
    Views:
    472
    Home_Job_opportunity
    Jan 8, 2009
  5. Bill Cunningham

    functio to load struct

    Bill Cunningham, Jun 6, 2010, in forum: C Programming
    Replies:
    16
    Views:
    457
    Bill Cunningham
    Jun 7, 2010
Loading...

Share This Page