473,472 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ctype.h - macros or functions?

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
Jun 4 '06 #1
3 3394
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.
Jun 4 '06 #2
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
Jun 4 '06 #3
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
es*****@acm-dot-org.invalid
Jun 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
11
by: Ben Hetland | last post by:
....in certain cituations they can be useful if not for anything else, then at least for saving a lot of repetetetetetitititive typing. :-) Beyond the point of "do something better instead", I'm...
5
by: Durgesh Sharma | last post by:
Are there no genric Macros in c to represent Integers,Characters,...or other data types ? I want to pass that MACRO (representing an alpha numeric Character)to that strrchar() function,to get the...
3
by: Stephen Sprunk | last post by:
On a project I'm working on, I ran across the following macros: /* assume s is struct stream *, s->p is char, v is unit16_t or uint32_t */ #define in_uint16_le(s,v) { v = *((s)->p++); v +=...
6
by: bharath539 | last post by:
hi anyone plz help in knowing about the ctype and its usage
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
8
by: =?Utf-8?B?d2lubGlu?= | last post by:
Hello Everything in .Net is an object and CTYPE converts one datatype to another datatype so why use Cstr, Cint or any other method to convert from one datatype to another?
19
by: Taras_96 | last post by:
Hi all, A poster at http://bytes.com/forum/thread60652.html implies that using strtoupper in transform doesn't work because ctype.h may define strtoupper as a macro: "The problem is that most...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.