This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Declaration of isspace in C/C++ not consistent?


On Sunday 02 June 2013 10:45:21 Hongxu Chen wrote:
> Hi list,
> 
> Maybe this question is a bit silly, but I just cannot understand why
> `isspace` seems not consistent for C and C++(I have put this question in
> stackoverflow but no satisfactory answer has been given yet).
> 
> I am using *clang* analyzer to get the definition information and I know
> quite little about the mechanism behind it, so the declaration result
> might not be accurate; but I am just confused.
> 
> For c code like this:
> 
>     // test.c
>     #include <ctype.h>
>     int main(int argc, char *argv[]) {
>       isspace('a');
>       return 0;
>     }
> 
> clang reports below as the declaration of isspace:
> 
>     # define isspace(c)	__isctype((c), _ISspace)  // LINE 207 in
> /usr/include/ctype.h
> 
> and when for this snippet:
> 
>     // test.cpp
>     #include <cctype>
>     int main() {
>       std::isspace('t');
>       return 0;
>     }
> 
> clang reports the declaration here:
> 
>     __exctype (isspace);  // LINE 120 in /usr/include/ctype.h
>     // #define	__exctype(name)	extern int name (int) __THROW
> 
> So why should there be such a difference?

glibc provides ctype.h which follows POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/ctype.h.html
we provide both real funcs and macros for each because the standard allows it, 
and the macro ends up producing better code at runtime.

gcc provides cctype which follows various C++ standards.
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]