function overloading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Sprunk

    #16
    Re: function overloading

    "Tor Rustad" <tor_rustad@hot mail.comwrote in message
    news:1163805186 .056312.19880@m 73g2000cwd.goog legroups.com...
    Stephen Sprunk skrev:
    >My implementation does something similar to this:
    >>
    >int foo_char(char x);
    >int foo_int(int x);
    >#define foo(x) { if (sizeof(x)==siz eof(char)) foo_char(x); else
    >foo_int(x); }
    >
    You should consider using the macro
    >
    #define foo(x) ((sizeof((x))== sizeof(char) ? (foo_char((x))) :
    (foo_int)((x)))
    >
    instead. However, this will not work in cases like
    >
    foo( foo(x) )
    >
    so I guess most C99 implementations use compiler magic
    >
    #define foo(x) __foo_generic(( x), foo_char, foo_int)
    My example was from the Linux/GCC/Glibc headers on my system. I did
    paraphrase a bit, to make things clearer since there were multiple
    levels of macros obscuring things, but that's pretty much what one will
    end up with after preprocessing.

    I'm curious what the failure modes are, if any, with that construction.

    S

    --
    Stephen Sprunk "God does not play dice." --Albert Einstein
    CCIE #3723 "God is an inveterate gambler, and He throws the
    K5SSS dice at every possible opportunity." --Stephen Hawking



    --
    Posted via a free Usenet account from http://www.teranews.com

    Comment

    Working...