Re: The Advantage of Macros

Discussion in 'C Programming' started by ¬a\\/b, Aug 16, 2007.

  1. ¬a\\/b

    ¬a\\/b Guest

    On Thu, 16 Aug 2007 07:08:24 -0700, "" wrote:
    >On Aug 16, 5:21 am, "¬a\\/b" <> wrote:
    >> On Tue, 14 Aug 2007 08:43:37 -0400, JDavison wrote:
    >> >What advantage or benefit does using a macro have over using a subroutine?

    >>
    >> in how i see: macros are useful only for build an assembly language
    >>
    >> they have little [or no] utility in other languages


    i say in C macros have little utility

    >Nonsense.
    >LISP, Dylan, and even C/C++ programmers would disagree strongly. And
    >these are just a few of the HLL that support macro capabilities.
    >hLater,
    >Randy Hyde
    ¬a\\/b, Aug 16, 2007
    #1
    1. Advertising

  2. ¬a\\/b

    Richard Bos Guest

    "¬a\\/b" <> wrote:

    > On Thu, 16 Aug 2007 07:08:24 -0700, "" wrote:
    > >On Aug 16, 5:21 am, "¬a\\/b" <> wrote:
    > >> On Tue, 14 Aug 2007 08:43:37 -0400, JDavison wrote:
    > >> >What advantage or benefit does using a macro have over using a subroutine?
    > >>
    > >> in how i see: macros are useful only for build an assembly language
    > >>
    > >> they have little [or no] utility in other languages

    >
    > i say in C macros have little utility


    I say you are a cross-posting troll. Stop that.

    Richard
    Richard Bos, Aug 16, 2007
    #2
    1. Advertising

  3. ¬a\\/b

    ¬a\\/b Guest

    On Thu, 16 Aug 2007 15:30:00 GMT, (Richard Bos) wrote:
    >"¬a\\/b" <> wrote:
    >> On Thu, 16 Aug 2007 07:08:24 -0700, "" wrote:
    >> >On Aug 16, 5:21 am, "¬a\\/b" <> wrote:
    >> >> On Tue, 14 Aug 2007 08:43:37 -0400, JDavison wrote:
    >> >> >What advantage or benefit does using a macro have over using a subroutine?
    >> >>
    >> >> in how i see: macros are useful only for build an assembly language
    >> >>
    >> >> they have little [or no] utility in other languages

    >>
    >> i say in C macros have little utility

    >
    >I say you are a cross-posting troll. Stop that.


    why did you seems not kill-file my name?
    do you have some interest what i have to say?

    >Richard
    ¬a\\/b, Aug 16, 2007
    #3
  4. ¬a\\/b

    SM Ryan Guest

    "¬a\\/b" <> wrote:
    # On Thu, 16 Aug 2007 07:08:24 -0700, "" wrote:
    # >On Aug 16, 5:21 am, "¬a\\/b" <> wrote:
    # >> On Tue, 14 Aug 2007 08:43:37 -0400, JDavison wrote:
    # >> >What advantage or benefit does using a macro have over using a subroutine?
    # >>
    # >> in how i see: macros are useful only for build an assembly language
    # >>
    # >> they have little [or no] utility in other languages
    #
    # i say in C macros have little utility

    If you're referring to #defines, they are not full macros.

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    The whole world's against us.
    SM Ryan, Aug 16, 2007
    #4
  5. "SM Ryan" <> wrote in
    message news:...
    >
    > # i say in C macros have little utility
    >
    > If you're referring to #defines, they are not full macros.
    >

    They're all we've got.
    I think it is generally accepted that the C macro system is a bit
    underpowered. There is for instance no unproblematic way of writing the
    "swap" macro.

    My "clamp" macro was recently criticised on the grounds that it evaluatees
    its arguements a variable number of times. clamp(*ptr++, 0, 100); is
    unlikely to do what you want. It was suggested that I write it in capital
    letters. Whether that advice was sound or not, you shouldn't have to do
    that. However if a macro is anywhere appropriate, it is in that sort of
    trivial function.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Aug 16, 2007
    #5
  6. SM Ryan <> writes:
    [...]
    > If you're referring to #defines, they are not full macros.


    How so? The C standard certainly refers to them as "macros". If
    there's some meaning to the term "full macros" that C's macros fail to
    fulfill, it's outside the scope of C.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Aug 16, 2007
    #6
  7. ¬a\\/b

    SM Ryan Guest

    "Malcolm McLean" <> wrote:
    #
    # "SM Ryan" <> wrote in
    # message news:...
    # >
    # > # i say in C macros have little utility
    # >
    # > If you're referring to #defines, they are not full macros.
    # >
    # They're all we've got.

    They're all _you_ have got.

    I've got real macros for my use.

    # I think it is generally accepted that the C macro system is a bit
    # underpowered. There is for instance no unproblematic way of writing the
    # "swap" macro.

    Lexical macros by design do not have context like variable types.
    For that you need syntax macros.

    --
    SM Ryan http://www.rawbw.com/~wyrmwif/
    You face forward, or you face the possibility of shock and damage.
    SM Ryan, Aug 17, 2007
    #7
  8. ¬a\\/b

    santosh Guest

    Frank Kotler wrote:

    > santosh wrote:
    >> Frank Kotler wrote:
    >>
    >>
    >>>¬a\/b wrote:
    >>>
    >>>...
    >>>
    >>>>i say in C macros have little utility
    >>>
    >>>You've heard of "printf", eh?

    >>
    >>
    >> Care to elaborate?

    >
    > Unless I'm mistaken, "printf" is frequently implemented as a macro. I'm
    > no C expert, so I could well be mistaken. Anyone know anything about
    > this, or do we have to add comp.lang.c back to the header?


    I think you might be thinking of putc/getc etc. I don't think printf is
    commonly implemented as a macro.
    santosh, Aug 17, 2007
    #8
  9. On Aug 16, 11:14 pm, santosh <> wrote:
    > Frank Kotler wrote:
    > > Unless I'm mistaken, "printf" is frequently implemented as a macro. I'm
    > > no C expert, so I could well be mistaken. Anyone know anything about
    > > this, or do we have to add comp.lang.c back to the header?

    >
    > I think you might be thinking of putc/getc etc. I don't think printf is
    > commonly implemented as a macro.


    In C90, if I'm not mistaken, it would even be impossible, because
    variadic macros weren't standardized until C99.
    Justin Spahr-Summers, Aug 17, 2007
    #9
  10. ¬a\\/b

    pete Guest

    santosh wrote:
    >
    > Frank Kotler wrote:
    >
    > > santosh wrote:
    > >> Frank Kotler wrote:
    > >>
    > >>
    > >>>¬a\/b wrote:
    > >>>
    > >>>...
    > >>>
    > >>>>i say in C macros have little utility
    > >>>
    > >>>You've heard of "printf", eh?
    > >>
    > >>
    > >> Care to elaborate?

    > >
    > > Unless I'm mistaken,
    > > "printf" is frequently implemented as a macro. I'm
    > > no C expert, so I could well be mistaken. Anyone know anything about
    > > this, or do we have to add comp.lang.c back to the header?

    >
    > I think you might be thinking of putc/getc etc.
    > I don't think printf is
    > commonly implemented as a macro.


    putchar is one of the et ceteras commonly implemented as a macro.

    --
    pete
    pete, Aug 17, 2007
    #10
  11. On Thu, 16 Aug 2007 14:27:55 -0700, in comp.lang.c , Keith Thompson
    <> wrote:

    >SM Ryan <> writes:
    >[...]
    >> If you're referring to #defines, they are not full macros.

    >
    >How so? The C standard certainly refers to them as "macros". If
    >there's some meaning to the term "full macros" that C's macros fail to
    >fulfill, it's outside the scope of C.


    I suspect Malcolm is thinking of macros in the sense that is used for
    extensions to editors, spreadsheets etc. I must say I always find the
    C terminology slightly peculiar when applied to what is essentially an
    alias for a constant. That doesn't stop me referring to them as macros
    mind you.
    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
    Mark McIntyre, Aug 17, 2007
    #11
  12. In article <>,
    Mark McIntyre <> wrote:

    >I suspect Malcolm is thinking of macros in the sense that is used for
    >extensions to editors, spreadsheets etc. I must say I always find the
    >C terminology slightly peculiar when applied to what is essentially an
    >alias for a constant. That doesn't stop me referring to them as macros
    >mind you.


    The only thing you can say about macros in general in computer science
    is that they are textual substitutions, and even that has been
    stretched, for example by various lisps, which substitute expressions
    rather than text as well as providing mechanisms to avoid name
    capture. C's macros are nearer the bottom end.

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
    Richard Tobin, Aug 17, 2007
    #12
  13. "santosh" <> wrote in message
    news:fa37be$rup$...
    >> Unless I'm mistaken, "printf" is frequently implemented as a macro. I'm
    >> no C expert, so I could well be mistaken. Anyone know anything about
    >> this, or do we have to add comp.lang.c back to the header?

    >
    > I think you might be thinking of putc/getc etc. I don't think printf is
    > commonly implemented as a macro.
    >

    I've seen the symbol printf redefined as a platform-specific call,
    presumably to help out the linker.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Aug 17, 2007
    #13
  14. "Mark McIntyre" <> wrote in message
    news:...
    > On Thu, 16 Aug 2007 14:27:55 -0700, in comp.lang.c , Keith Thompson
    > <> wrote:
    >
    >>SM Ryan <> writes:
    >>[...]
    >>> If you're referring to #defines, they are not full macros.

    >>
    >>How so? The C standard certainly refers to them as "macros". If
    >>there's some meaning to the term "full macros" that C's macros fail to
    >>fulfill, it's outside the scope of C.

    >
    > I suspect Malcolm is thinking of macros in the sense that is used for
    > extensions to editors, spreadsheets etc. I must say I always find the
    > C terminology slightly peculiar when applied to what is essentially an
    > alias for a constant. That doesn't stop me referring to them as macros
    > mind you.
    >

    I am not quoted here. I said the C macro system was underpowered, but I
    didn't try to define the word.

    --
    Free games and programming goodies.
    http://www.personal.leeds.ac.uk/~bgy1mm
    Malcolm McLean, Aug 17, 2007
    #14
  15. On Fri, 17 Aug 2007 22:32:38 +0100, in comp.lang.c , "Malcolm McLean"
    <> wrote:

    >
    >"Mark McIntyre" <> wrote in message
    >news:...
    >> On Thu, 16 Aug 2007 14:27:55 -0700, in comp.lang.c , Keith Thompson
    >> <> wrote:
    >>
    >>>SM Ryan <> writes:
    >>>[...]
    >>>> If you're referring to #defines, they are not full macros.
    >>>
    >>>How so? The C standard certainly refers to them as "macros". If
    >>>there's some meaning to the term "full macros" that C's macros fail to
    >>>fulfill, it's outside the scope of C.

    >>
    >> I suspect Malcolm is thinking of macros in the sense that is used for
    >> extensions to editors, spreadsheets etc. I must say I always find the
    >> C terminology slightly peculiar when applied to what is essentially an
    >> alias for a constant. That doesn't stop me referring to them as macros
    >> mind you.
    >>

    >I am not quoted here.


    Apologies, I misread (or possibly failed to read) the attribs.
    --
    Mark McIntyre

    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
    Mark McIntyre, Aug 17, 2007
    #15
    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. Replies:
    80
    Views:
    2,417
    Stephen J. Bevan
    Nov 7, 2003
  2. Replies:
    1
    Views:
    439
    Marco Antoniotti
    Oct 7, 2003
  3. Replies:
    5
    Views:
    495
  4. Michael T. Babcock

    Re: Explanation of macros; Haskell macros

    Michael T. Babcock, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    515
    Michael T. Babcock
    Nov 3, 2003
  5. Andrew Arro

    macros-loop? calling macros X times?

    Andrew Arro, Jul 23, 2004, in forum: C Programming
    Replies:
    2
    Views:
    491
    S.Tobias
    Jul 24, 2004
Loading...

Share This Page