Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > ctype.h - macros or functions?

Reply
Thread Tools

ctype.h - macros or functions?

 
 
Michael Brennan
Guest
Posts: n/a
 
      06-04-2006
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
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      06-04-2006
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


 
Reply With Quote
 
 
 
 
Tim Prince
Guest
Posts: n/a
 
      06-04-2006
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.
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      06-04-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macros-loop? calling macros X times? Andrew Arro C Programming 2 07-24-2004 09:52 AM
Explanation of macros; Haskell macros mike420@ziplip.com Python 80 11-07-2003 02:22 AM
Re: Explanation of macros; Haskell macros Michael T. Babcock Python 0 11-03-2003 01:54 PM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 5 11-01-2003 01:09 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 1 10-07-2003 04:07 PM



Advertisments