ctype.h - macros or functions?

  • Thread starter Michael Brennan
  • Start date
M

Michael Brennan

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
 
C

CBFalconer

Michael said:
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:
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
 
T

Tim Prince

Michael said:
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.
 
E

Eric Sosman

Michael said:
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,520
Latest member
KrisMacono

Latest Threads

Top