public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
@ 2006-10-05 21:10 Kevin O'Gorman
  2006-10-06  0:04 ` Boyd Stephen Smith Jr.
  2006-10-06  0:53 ` Boyd Stephen Smith Jr.
  0 siblings, 2 replies; 12+ messages in thread
From: Kevin O'Gorman @ 2006-10-05 21:10 UTC (permalink / raw
  To: gentoo-user

Why is it that using some of the macros from ctype.h fails to compile?
In particular, the three mentioned in the subject: line.

Try this:

#include <stdio.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
    int i;
    for (i = 0; i < 256; i++) {
        printf("%3d: ",i);
        if (isalpha(i)) printf(" alpha");
        if (isalnum(i)) printf(" alnum");
        if (isascii(i)) printf(" ascii");
        if (isblank(i)) printf(" blank");
        if (iscntrl(i)) printf(" cntrl");
        if (isdigit(i)) printf(" digit");
        if (isgraph(i)) printf(" graph");
        if (islower(i)) printf(" lower");
        if (isprint(i)) printf(" print");
        if (ispunct(i)) punctf(" punct");
        if (isspace(i)) printf(" space");
        if (isupper(i)) printf(" upper");
        if (isxdigit(i)) printf(" xdigit");
        printf("\n");
    }

    return 0;
}


-- 
Kevin O'Gorman, PhD
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-05 21:10 [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails Kevin O'Gorman
@ 2006-10-06  0:04 ` Boyd Stephen Smith Jr.
  2006-10-06  0:53 ` Boyd Stephen Smith Jr.
  1 sibling, 0 replies; 12+ messages in thread
From: Boyd Stephen Smith Jr. @ 2006-10-06  0:04 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 853 bytes --]

On Thursday 05 October 2006 16:10, "Kevin O'Gorman" <kogorman@gmail.com> 
wrote about '[gentoo-user] C programming use of isascii(), ispunct() and 
isblank() fails':
> Why is it that using some of the macros from ctype.h fails to compile?
> In particular, [isascii, ispuncy, and isblank].

I'd be nice if you you let use know the errors you are seeing.  Many of us 
may have a different configuration and be unable to reproduce errors; and 
most of us are neither mind readers nor precognitive so we wouldn't know 
if we'd reproduced the errors or not.

http://www.catb.org/~esr/faqs/smart-questions.html#symptoms

-- 
"If there's one thing we've established over the years,
it's that the vast majority of our users don't have the slightest
clue what's best for them in terms of package stability."
-- Gentoo Developer Ciaran McCreesh

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-05 21:10 [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails Kevin O'Gorman
  2006-10-06  0:04 ` Boyd Stephen Smith Jr.
@ 2006-10-06  0:53 ` Boyd Stephen Smith Jr.
  2006-10-06  2:32   ` Kevin O'Gorman
  1 sibling, 1 reply; 12+ messages in thread
From: Boyd Stephen Smith Jr. @ 2006-10-06  0:53 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 754 bytes --]

On Thursday 05 October 2006 16:10, "Kevin O'Gorman" <kogorman@gmail.com> 
wrote about '[gentoo-user] C programming use of isascii(), ispunct() and 
isblank() fails':
> Why is it that using some of the macros from ctype.h fails to compile?

You code compiles fine for me.  I'm using... hrm, an invalid profile... 
well, gcc --version reports 'gcc (GCC) 4.1.1 (Gentoo 4.1.1-r1)'

>         if (ispunct(i)) punctf(" punct");

I did get a link error, because you haven't defined "punctf"; I'll bet you 
meant "printf".

-- 
"If there's one thing we've established over the years,
it's that the vast majority of our users don't have the slightest
clue what's best for them in terms of package stability."
-- Gentoo Developer Ciaran McCreesh

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06  0:53 ` Boyd Stephen Smith Jr.
@ 2006-10-06  2:32   ` Kevin O'Gorman
  2006-10-06  2:58     ` Mark Kirkwood
                       ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Kevin O'Gorman @ 2006-10-06  2:32 UTC (permalink / raw
  To: gentoo-user

On 10/5/06, Boyd Stephen Smith Jr. <bss03@volumehost.net> wrote:
> On Thursday 05 October 2006 16:10, "Kevin O'Gorman" <kogorman@gmail.com>
> wrote about '[gentoo-user] C programming use of isascii(), ispunct() and
> isblank() fails':
> > Why is it that using some of the macros from ctype.h fails to compile?
>
> You code compiles fine for me.  I'm using... hrm, an invalid profile...
> well, gcc --version reports 'gcc (GCC) 4.1.1 (Gentoo 4.1.1-r1)'
>
> >         if (ispunct(i)) punctf(" punct");
>
> I did get a link error, because you haven't defined "punctf"; I'll bet you
> meant "printf".
>

-- 
Kevin O'Gorman, PhD

Hmmm.  I did indeed mean printf -- a goof in s/// stuff.  Anyway, even after
that,when I
gcc -Wall ctype.c -o ctype
I get
ctype.c:21: warning: implicit declaration of function 'isblank'

and I get more of these if I use -ansi.  I can get rid of it by removing -Wall,
but my normal practice is the opposite: I add -Werror.  I'd just like to know
how to make it clean.

++ kevin
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06  2:32   ` Kevin O'Gorman
@ 2006-10-06  2:58     ` Mark Kirkwood
  2006-10-06  3:19     ` Bo Ørsted Andresen
  2006-10-06 14:31     ` Arturo 'Buanzo' Busleiman
  2 siblings, 0 replies; 12+ messages in thread
From: Mark Kirkwood @ 2006-10-06  2:58 UTC (permalink / raw
  To: gentoo-user

Kevin O'Gorman wrote:
> On 10/5/06, Boyd Stephen Smith Jr. <bss03@volumehost.net> wrote:
>> On Thursday 05 October 2006 16:10, "Kevin O'Gorman" <kogorman@gmail.com>
>> wrote about '[gentoo-user] C programming use of isascii(), ispunct() and
>> isblank() fails':
>> > Why is it that using some of the macros from ctype.h fails to compile?
>>
>> You code compiles fine for me.  I'm using... hrm, an invalid profile...
>> well, gcc --version reports 'gcc (GCC) 4.1.1 (Gentoo 4.1.1-r1)'
>>
>> >         if (ispunct(i)) punctf(" punct");
>>
>> I did get a link error, because you haven't defined "punctf"; I'll bet 
>> you
>> meant "printf".
>>
> 

FWIW - I get "implicit declaration of function 'isblank'" as well - 
system is:

Portage 2.1.1 (default-linux/x86/2006.0, gcc-4.1.1, glibc-2.4-r3, 
2.6.17-gentoo-r8 i686)

If I add '-D_GNU_SOURCE' to the compile line then it goes away. Not sure 
if this is the intended behavior tho...


regards

Mark
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06  2:32   ` Kevin O'Gorman
  2006-10-06  2:58     ` Mark Kirkwood
@ 2006-10-06  3:19     ` Bo Ørsted Andresen
  2006-10-06  4:49       ` Kevin O'Gorman
  2006-10-06 14:31     ` Arturo 'Buanzo' Busleiman
  2 siblings, 1 reply; 12+ messages in thread
From: Bo Ørsted Andresen @ 2006-10-06  3:19 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 225 bytes --]

On Friday 06 October 2006 04:32, Kevin O'Gorman wrote:
> gcc -Wall ctype.c -o ctype
> I get
> ctype.c:21: warning: implicit declaration of function 'isblank'

$ gcc -std=gnu99 -Wall ctype.c -o ctype

-- 
Bo Andresen

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06  3:19     ` Bo Ørsted Andresen
@ 2006-10-06  4:49       ` Kevin O'Gorman
  2006-10-06  4:55         ` Bo Ørsted Andresen
                           ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Kevin O'Gorman @ 2006-10-06  4:49 UTC (permalink / raw
  To: gentoo-user

On 10/5/06, Bo Ørsted Andresen <bo.andresen@zlin.dk> wrote:
> On Friday 06 October 2006 04:32, Kevin O'Gorman wrote:
> > gcc -Wall ctype.c -o ctype
> > I get
> > ctype.c:21: warning: implicit declaration of function 'isblank'
>
> $ gcc -std=gnu99 -Wall ctype.c -o ctype
>
> --
> Bo Andresen

Why would this need a GNU-specific flag?  Aren't these things some
level of POSIX?  (I'm only guessing; FSF may well have added one
or two, and I want to know either way).

++ kevin

-- 
Kevin O'Gorman, PhD

-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06  4:49       ` Kevin O'Gorman
@ 2006-10-06  4:55         ` Bo Ørsted Andresen
  2006-10-06  5:00         ` Richard Fish
       [not found]         ` <200610060750.40927.bss03@volumehost.net>
  2 siblings, 0 replies; 12+ messages in thread
From: Bo Ørsted Andresen @ 2006-10-06  4:55 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]

On Friday 06 October 2006 06:49, Kevin O'Gorman wrote:
> On 10/5/06, Bo Ørsted Andresen <bo.andresen@zlin.dk> wrote:
> > On Friday 06 October 2006 04:32, Kevin O'Gorman wrote:
> > > gcc -Wall ctype.c -o ctype
> > > I get
> > > ctype.c:21: warning: implicit declaration of function 'isblank'
> >
> > $ gcc -std=gnu99 -Wall ctype.c -o ctype
>
> Why would this need a GNU-specific flag?  Aren't these things some
> level of POSIX?  (I'm only guessing; FSF may well have added one
> or two, and I want to know either way).

After sending the previous mail I figured I probably should have eloborated a 
bit. I didn't actually bother to look up the standards but instead I looked 
in <ctype.h> to find this info...

$ gcc -Wall -o test-kev test-kev.c
test-kev.c: In function ‘main’:
test-kev.c:15: advarsel: implicit declaration of function ‘isblank’
$ gcc -std=c99 -Wall -o test-kev test-kev.c
test-kev.c: In function ‘main’:
test-kev.c:14: advarsel: implicit declaration of function ‘isascii’
$ gcc -std=gnu99 -Wall -o test-kev test-kev.c
$ 

The point is unless someone made a mistake in <ctype.h> isblank is part of the 
C99 standard and isascii is a GNU extension...

-- 
Bo Andresen

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06  4:49       ` Kevin O'Gorman
  2006-10-06  4:55         ` Bo Ørsted Andresen
@ 2006-10-06  5:00         ` Richard Fish
       [not found]         ` <200610060750.40927.bss03@volumehost.net>
  2 siblings, 0 replies; 12+ messages in thread
From: Richard Fish @ 2006-10-06  5:00 UTC (permalink / raw
  To: gentoo-user

On 10/5/06, Kevin O'Gorman <kogorman@gmail.com> wrote:
> Why would this need a GNU-specific flag?  Aren't these things some
> level of POSIX?  (I'm only guessing; FSF may well have added one
> or two, and I want to know either way).

>From the ctype.h header file:

/* ISO C99 introduced one new function.  */
#ifdef  __USE_ISOC99
__BEGIN_NAMESPACE_C99

__exctype (isblank);

__END_NAMESPACE_C99
#endif

So isblank is only defined for the C99 namespace, which you get with
either -std=c99 or -std=gnu99 (from the gnu info page).

-Richard
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
       [not found]         ` <200610060750.40927.bss03@volumehost.net>
@ 2006-10-06 14:29           ` Arturo 'Buanzo' Busleiman
  0 siblings, 0 replies; 12+ messages in thread
From: Arturo 'Buanzo' Busleiman @ 2006-10-06 14:29 UTC (permalink / raw
  To: gentoo-user

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Boyd Stephen Smith Jr. wrote:
> The C89 standard I work off of [1] doesn't list isascii or isblank.  They 
> must have been added in either C99 or by the GNU project.  I'm not sure 
> what standard (or standard + extensions) gcc defaults to, but I'll bet 
> it's mentioned in it's info pages.

man isascii:

CONFORMING TO
       C99,  4.3BSD.   isascii()  is a BSD extension and is also an SVr4 extension.  isblank() con-
       forms to POSIX.1-2001 and C99 7.4.1.3.


- --
Arturo "Buanzo" Busleiman - Consultor Independiente en Seguridad Informatica
"Do you know about the dangers of DRM? Find out at http://www.defectivebydesign.org/what_is_drm"

http://www.buanzo.com.ar | http://www.vivamoslavida.com.ar : Portal no-comercial del buen vivir!
for f in www blog linux-consulting vpnmail; do firefox http://$f.buanzo.com.ar ; done
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFJmhdAlpOsGhXcE0RAiufAJ4rsc1fccktxIf9Eqe2VkQAnZVC8ACeJCgf
5KWq7n4tSSFAfU4FdOZmC8g=
=+lmD
-----END PGP SIGNATURE-----
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06  2:32   ` Kevin O'Gorman
  2006-10-06  2:58     ` Mark Kirkwood
  2006-10-06  3:19     ` Bo Ørsted Andresen
@ 2006-10-06 14:31     ` Arturo 'Buanzo' Busleiman
  2006-10-11  1:40       ` Zac Slade
  2 siblings, 1 reply; 12+ messages in thread
From: Arturo 'Buanzo' Busleiman @ 2006-10-06 14:31 UTC (permalink / raw
  To: gentoo-user

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

gcc -o digits -Wall -ansi -pedantic digits.c

With that, I got the "implicit declaration of function BLAH" message. When that happens, and the man
page does not list anything special, I usually add this at the beginning of the source file:

#define _GNU_SOURCE

et voila', now compiles cleanly

- --
Arturo "Buanzo" Busleiman - Consultor Independiente en Seguridad Informatica
"Do you know about the dangers of DRM? Find out at http://www.defectivebydesign.org/what_is_drm"

http://www.buanzo.com.ar | http://www.vivamoslavida.com.ar : Portal no-comercial del buen vivir!
for f in www blog linux-consulting vpnmail; do firefox http://$f.buanzo.com.ar ; done
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFJmi4AlpOsGhXcE0RAgbxAJ0Y6iCfQhkSRJhtw+P7DYs8UmDM9ACffEhx
jtef6SeHVVgG0l2tAjzsDTo=
=ezDJ
-----END PGP SIGNATURE-----
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails
  2006-10-06 14:31     ` Arturo 'Buanzo' Busleiman
@ 2006-10-11  1:40       ` Zac Slade
  0 siblings, 0 replies; 12+ messages in thread
From: Zac Slade @ 2006-10-11  1:40 UTC (permalink / raw
  To: gentoo-user

On Friday 06 October 2006 09:31, Arturo 'Buanzo' Busleiman wrote:
> gcc -o digits -Wall -ansi -pedantic digits.c
>
> With that, I got the "implicit declaration of function BLAH" message. When
> that happens, and the man page does not list anything special, I usually
> add this at the beginning of the source file:
>
> #define _GNU_SOURCE
>
> et voila', now compiles cleanly
Yes but this is still entirely wrong....  Come on people let's at least try to 
be standards based.

If you really want isascii() and isblank() then you need this 
#define _XOPEN_SOURCE 600

Without the above define:
gcc -Wall -pedantic ctype.c -o ctype
ctype.c: In function 'main':
ctype.c:13: warning: implicit declaration of function 'isascii'
ctype.c:14: warning: implicit declaration of function 'isblank'

With the above define:
gcc -Wall -pedantic ctype.c -o ctype

This is needed for "A Strictly Conforming POSIX Application."  If you read the 
SUSv3 it states that you should define _POSIX_C_SOURCE to 200112L, but that 
this is redundant if you define _XOPEN_SOURCE to 600.  Now realistically you 
should not be defining it yourself, you should be testing for compliance then 
using what is available.

Please let's not try and make code completely unportable to different 
compilers just cause we all like gcc.  There may be a day that another 
compiler comes along that is way better than gcc and by using _GNU_SOURCE you 
are locked in.

We do have standards.  They are sometimes a little hard to read and sometimes 
you just can't get the behavior you want by following them, try to use them 
when possible and be aware of the standards that functions are defined in on 
their man pages.
-- 
Zac Slade
krakrjak@volumehost.net
ICQ:1415282 YM:krakrjak AIM:ttyp99
-- 
gentoo-user@gentoo.org mailing list



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2006-10-11  1:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-05 21:10 [gentoo-user] C programming use of isascii(), ispunct() and isblank() fails Kevin O'Gorman
2006-10-06  0:04 ` Boyd Stephen Smith Jr.
2006-10-06  0:53 ` Boyd Stephen Smith Jr.
2006-10-06  2:32   ` Kevin O'Gorman
2006-10-06  2:58     ` Mark Kirkwood
2006-10-06  3:19     ` Bo Ørsted Andresen
2006-10-06  4:49       ` Kevin O'Gorman
2006-10-06  4:55         ` Bo Ørsted Andresen
2006-10-06  5:00         ` Richard Fish
     [not found]         ` <200610060750.40927.bss03@volumehost.net>
2006-10-06 14:29           ` Arturo 'Buanzo' Busleiman
2006-10-06 14:31     ` Arturo 'Buanzo' Busleiman
2006-10-11  1:40       ` Zac Slade

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox