typedef v macro

Discussion in 'C Programming' started by Uno, Dec 1, 2010.

  1. Uno

    Uno Guest

    Hello ng,

    I hope this message finds you all well. It's been a while since I've
    had any real time to devote to programming and usenet, and while I'll
    hope to stay busy as a handyman through the winter, I'll take it as the
    silver lining that I can pursue avocation and hobby otherwise.

    Keith posted this source in comp.std.c:

    $ gcc -Wall -Wextra e2.c -o out
    $ ./out
    float_t is not a macro
    $ cat e2.c
    #include <math.h>
    #include <stdio.h>
    int main(void)
    {
    #ifdef float_t
    puts("float_t is a macro");
    #else
    puts("float_t is not a macro");
    #endif
    return 0;
    }
    // gcc -Wall -Wextra e2.c -o out
    $

    1) I'm looking for general comments on the above. including whether you
    get different output.

    2) Can a conforming implementation render the other possibility?

    Thanks for your comment,
    and cheers,
    --
    Uno
     
    Uno, Dec 1, 2010
    #1
    1. Advertising

  2. Uno <> writes:
    > I hope this message finds you all well. It's been a while since I've
    > had any real time to devote to programming and usenet, and while I'll
    > hope to stay busy as a handyman through the winter, I'll take it as the
    > silver lining that I can pursue avocation and hobby otherwise.
    >
    > Keith posted this source in comp.std.c:
    >
    > $ gcc -Wall -Wextra e2.c -o out
    > $ ./out
    > float_t is not a macro
    > $ cat e2.c
    > #include <math.h>
    > #include <stdio.h>
    > int main(void)
    > {
    > #ifdef float_t
    > puts("float_t is a macro");
    > #else
    > puts("float_t is not a macro");
    > #endif
    > return 0;
    > }
    > // gcc -Wall -Wextra e2.c -o out
    > $
    >
    > 1) I'm looking for general comments on the above. including whether you
    > get different output.
    >
    > 2) Can a conforming implementation render the other possibility?


    If you wanted to discuss this, surely it would have made more
    sense to post a followup in comp.std.c rather than starting a new
    thread here in comp.lang.c. You could at least have refered to,
    or even quoted, the argument I made there that float_t *cannot*
    be a macro in a conforming implementation.

    I believe the following program is strictly conforming:

    #include <math.h>
    int main(void) {
    int float_t;
    return 0;
    }

    If float_t were a macro usable as a type name, it would fail
    to compile.

    I do think the Standard would be slighly clearer if it stated
    explicitly that the types defined in the various standard headers
    are typedefs.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 1, 2010
    #2
    1. Advertising

  3. Uno

    Uno Guest

    Keith Thompson wrote:
    > Uno <> writes:
    >> I hope this message finds you all well. It's been a while since I've
    >> had any real time to devote to programming and usenet, and while I'll
    >> hope to stay busy as a handyman through the winter, I'll take it as the
    >> silver lining that I can pursue avocation and hobby otherwise.
    >>
    >> Keith posted this source in comp.std.c:
    >>
    >> $ gcc -Wall -Wextra e2.c -o out
    >> $ ./out
    >> float_t is not a macro
    >> $ cat e2.c
    >> #include <math.h>
    >> #include <stdio.h>
    >> int main(void)
    >> {
    >> #ifdef float_t
    >> puts("float_t is a macro");
    >> #else
    >> puts("float_t is not a macro");
    >> #endif
    >> return 0;
    >> }
    >> // gcc -Wall -Wextra e2.c -o out
    >> $
    >>
    >> 1) I'm looking for general comments on the above. including whether you
    >> get different output.
    >>
    >> 2) Can a conforming implementation render the other possibility?

    >
    > If you wanted to discuss this, surely it would have made more
    > sense to post a followup in comp.std.c rather than starting a new
    > thread here in comp.lang.c. You could at least have refered to,
    > or even quoted, the argument I made there that float_t *cannot*
    > be a macro in a conforming implementation.


    No, I made the right decision to start a new thread, for a variety of
    reasons, and since humor and honoring the recently-departed is always on
    topic in clc, my name's not Shirley.

    I thought the previous thread very successful in solving many of the
    problems with floating point, if only because, when exposed to a larger
    audience, they didn't seem to be problems so much as challenges.

    Also, crossposted stuff needs to have an expiration date, or heterodoxy
    devolves into a flamy thing. I hardly remember all of the context by
    now, but I knew that next time I got on usenet, I wanted to feed your
    source to gcc and pick up there.
    >
    > I believe the following program is strictly conforming:
    >
    > #include <math.h>
    > int main(void) {
    > int float_t;
    > return 0;
    > }
    >
    > If float_t were a macro usable as a type name, it would fail
    > to compile.


    Ok. No one seems to object. Can one imitate a typedef with a macro as
    a useful, non-standard hack?
    >
    > I do think the Standard would be slighly clearer if it stated
    > explicitly that the types defined in the various standard headers
    > are typedefs.
    >


    Can you give other examples here?
    --
    Uno
     
    Uno, Dec 3, 2010
    #3
  4. Uno <> writes:
    > Keith Thompson wrote:
    >> Uno <> writes:
    >>> I hope this message finds you all well. It's been a while since I've
    >>> had any real time to devote to programming and usenet, and while I'll
    >>> hope to stay busy as a handyman through the winter, I'll take it as the
    >>> silver lining that I can pursue avocation and hobby otherwise.
    >>>
    >>> Keith posted this source in comp.std.c:

    [snip]
    >> If you wanted to discuss this, surely it would have made more
    >> sense to post a followup in comp.std.c rather than starting a new
    >> thread here in comp.lang.c. You could at least have refered to,
    >> or even quoted, the argument I made there that float_t *cannot*
    >> be a macro in a conforming implementation.

    >
    > No, I made the right decision to start a new thread, for a variety of
    > reasons, and since humor and honoring the recently-departed is always on
    > topic in clc, my name's not Shirley.


    Yes, Mr. Nielsen will indeed be missed.

    As for starting a new thread being "the right decision", I'm at a
    loss to follow your reasoning. And again, you snipped the part of
    the article you quoted in which I answered the very question you
    were asking.

    [...]
    >> I do think the Standard would be slighly clearer if it stated
    >> explicitly that the types defined in the various standard headers
    >> are typedefs.
    >>

    >
    > Can you give other examples here?


    Probably.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Dec 5, 2010
    #4
    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. Dead RAM
    Replies:
    20
    Views:
    1,132
    John Harrison
    Jul 14, 2004
  2. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    590
    Jack Klein
    Sep 21, 2003
  3. Regarding typedef and macro

    , Dec 13, 2006, in forum: C Programming
    Replies:
    15
    Views:
    435
    Eric Sosman
    Dec 15, 2006
  4. oor
    Replies:
    0
    Views:
    1,373
  5. Tagore

    typedef v/s macro

    Tagore, Dec 24, 2008, in forum: C Programming
    Replies:
    1
    Views:
    1,547
    Keith Thompson
    Dec 24, 2008
Loading...

Share This Page