ctype.h - macros or functions?

Discussion in 'C Programming' started by Michael Brennan, Jun 4, 2006.

  1. Hi,
    does the standard say if the isalpha, isdigit, etc. functions
    in ctype.h are functions or macros?
    My old pre-ansi book says they are macros,
    but I've seen man pages that say they are
    functions and others that say they're macros.

    Thanks!

    /Michael
     
    Michael Brennan, Jun 4, 2006
    #1
    1. Advertising

  2. Michael Brennan

    CBFalconer Guest

    Michael Brennan wrote:
    >
    > does the standard say if the isalpha, isdigit, etc. functions
    > in ctype.h are functions or macros?
    > My old pre-ansi book says they are macros,
    > but I've seen man pages that say they are
    > functions and others that say they're macros.


    They can be either, but they must be available as functions (in
    order to take their address for function pointer passing). To
    ensure you get the functional form, enclose the name in
    parentheses, eg: "fnptr = (isalpha);". This applies to the entire
    standard library.

    --
    Some informative links:
    news:news.announce.newusers
    http://www.geocities.com/nnqweb/
    http://www.catb.org/~esr/faqs/smart-questions.html
    http://www.caliburn.nl/topposting.html
    http://www.netmeister.org/news/learn2quote.html
     
    CBFalconer, Jun 4, 2006
    #2
    1. Advertising

  3. Michael Brennan

    Tim Prince Guest

    Michael Brennan wrote:
    > Hi,
    > does the standard say if the isalpha, isdigit, etc. functions
    > in ctype.h are functions or macros?
    > My old pre-ansi book says they are macros,
    > but I've seen man pages that say they are
    > functions and others that say they're macros.
    >

    In principle, the C standard demands that function versions be
    available, should you choose to take the trouble to #undef each macro.
    Performance requires they should be in-lined, with macros being the
    proven method.
     
    Tim Prince, Jun 4, 2006
    #3
  4. Michael Brennan

    Eric Sosman Guest

    Michael Brennan wrote:
    > Hi,
    > does the standard say if the isalpha, isdigit, etc. functions
    > in ctype.h are functions or macros?
    > My old pre-ansi book says they are macros,
    > but I've seen man pages that say they are
    > functions and others that say they're macros.


    The Standard describes them as functions. However, the
    Standard allows an implementation to provide "masking" macros
    for any Standard functions, so long as they behave the same
    way the functions themselves do. (Almost "the same," that is:
    A macro expansion need not have the same sequence points an
    actual function call would, and the masking macros for a few
    functions like getc() are allowed a little more leeway.)

    If an implementation provides a masking macro for a function,
    it is not relieved of the responsibility to provide the actual
    function, too. This ensures that you can call the function via
    a function pointer even if a macro substitution would be used in
    "open code." You can also force the function to be used instead
    of the macro by writing, e.g., (sqrt)(42.0) instead of sqrt(42.0).

    --
    Eric Sosman
    lid
     
    Eric Sosman, Jun 4, 2006
    #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. Replies:
    80
    Views:
    2,449
    Stephen J. Bevan
    Nov 7, 2003
  2. Replies:
    1
    Views:
    463
    Marco Antoniotti
    Oct 7, 2003
  3. Replies:
    5
    Views:
    505
  4. Michael T. Babcock

    Re: Explanation of macros; Haskell macros

    Michael T. Babcock, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    530
    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:
    509
    S.Tobias
    Jul 24, 2004
Loading...

Share This Page