Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > portability issues with ' flag in printf

Reply
Thread Tools

portability issues with ' flag in printf

 
 
billposer@alum.mit.edu
Guest
Posts: n/a
 
      04-19-2006
The ' (single quote/apostrophe - ASCII 0x27) flag in *printf (which
causes delimitation of integer groups as per the locale) is not in the
C standard, and as applied to floats is not even in SUSv2. On the other
hand, it is very useful. I'm wondering how people check for
availability of a version of printf that supports it. I don't find a
macro for this in the autoconf macro library, and I'm hard put to write
my own because all of the systems to which I have easy access use
versions of gcc that support it so I don't know what the failure mode
is on systems that do not. How do other people handle this? Is there an
autoconf macro I don't know about? Or can someone who uses a compiler
that doesn't support it tell me whether it generates a syntax error at
compile time or a runtime error? Thanks.

 
Reply With Quote
 
 
 
 
Aki Tuomi
Guest
Posts: n/a
 
      04-19-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) kirjoitti:
> The ' (single quote/apostrophe - ASCII 0x27) flag in *printf (which
> causes delimitation of integer groups as per the locale) is not in the
> C standard, and as applied to floats is not even in SUSv2. On the other
> hand, it is very useful. I'm wondering how people check for
> availability of a version of printf that supports it. I don't find a
> macro for this in the autoconf macro library, and I'm hard put to write
> my own because all of the systems to which I have easy access use
> versions of gcc that support it so I don't know what the failure mode
> is on systems that do not. How do other people handle this? Is there an
> autoconf macro I don't know about? Or can someone who uses a compiler
> that doesn't support it tell me whether it generates a syntax error at
> compile time or a runtime error? Thanks.
>


Write your own test, see http://www.gnu.org/software/autoconf for
manual. It really isn't as hard as you might think.

Aki Tuomi
 
Reply With Quote
 
 
 
 
Vladimir S. Oka
Guest
Posts: n/a
 
      04-19-2006
(E-Mail Removed) opined:

> The ' (single quote/apostrophe - ASCII 0x27) flag in *printf (which
> causes delimitation of integer groups as per the locale) is not in
> the C standard, and as applied to floats is not even in SUSv2.


That'd make it off-topic here.

> On the other hand, it is very useful. I'm wondering how people check
> for availability of a version of printf that supports it.


By reading the documentation of their particular implementation?

> I don't find a macro for this in the autoconf macro library, and I'm
> hard put to write my own because all of the systems to which I have
> easy access use versions of gcc that support it so I don't know what
> the failure mode is on systems that do not. How do other people
> handle this? Is there an autoconf macro I don't know about?


All off-topic here.

> Or can someone who uses a compiler that doesn't support it tell me
> whether it generates a syntax error at compile time or a runtime
> error?


Presumably, people using implementations not supporting this (or who
never had use for it, as is my case), won't be familiar with the
correct syntax to check for you and tell the results.

Consider posting a legal `printf()` call using this. Maybe someone will
try it out and tell you what they got.

--
"Are [Linux users] lemmings collectively jumping off of the cliff of
reliable, well-engineered commercial software?"
(By Matt Welsh)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      04-19-2006
(E-Mail Removed) a écrit :
> The ' (single quote/apostrophe - ASCII 0x27) flag in *printf (which
> causes delimitation of integer groups as per the locale) is not in the
> C standard, and as applied to floats is not even in SUSv2. On the other
> hand, it is very useful. I'm wondering how people check for
> availability of a version of printf that supports it. I don't find a
> macro for this in the autoconf macro library, and I'm hard put to write
> my own because all of the systems to which I have easy access use
> versions of gcc that support it so I don't know what the failure mode
> is on systems that do not. How do other people handle this? Is there an
> autoconf macro I don't know about? Or can someone who uses a compiler
> that doesn't support it tell me whether it generates a syntax error at
> compile time or a runtime error? Thanks.
>



#include <stdio.h>
#include <string.h>
int main(void)
{
int ll = 87334455;
char buf[256];

sprintf(buf,"%'d\n",ll);
if (strchr(buf,'\''))
printf("This compiler does NOT support the ' qualifier\n");
else
printf("This compiler supports the ' qualifier\n");

}

Using Microsoft CL I obtain
This compiler does NOT support the ' qualifier
Using lcc-win32 I obtain
This compiler supports the ' qualifier
Using gcc I obtain
This compiler supports the ' qualifier


jacob
 
Reply With Quote
 
billposer@alum.mit.edu
Guest
Posts: n/a
 
      04-19-2006
>Write your own test, see http://www.gnu.org/software/autoconf for
>manual. It really isn't as hard as you might think.


I've written my own tests in the past, but I've always known what sort
of error to expect. If you don't, as in this case, the macro becomes
nastier.

 
Reply With Quote
 
billposer@alum.mit.edu
Guest
Posts: n/a
 
      04-19-2006
>> On the other hand, it is very useful. I'm wondering how people check
> >for availability of a version of printf that supports it.


>By reading the documentation of their particular implementation?


I guess you don't ever try to write portable C. I can't read the
documentation for
every C implementation. The idea is to anticipate implementations that
I don't know about.

>Presumably, people using implementations not supporting this (or who
>never had use for it, as is my case), won't be familiar with the
>correct syntax to check for you and tell the results.


Many people have used more than one implementation.

 
Reply With Quote
 
billposer@alum.mit.edu
Guest
Posts: n/a
 
      04-19-2006
Thanks very much. That is helpful.

 
Reply With Quote
 
billposer@alum.mit.edu
Guest
Posts: n/a
 
      04-19-2006
>> The ' (single quote/apostrophe - ASCII 0x27) flag in *printf (which
>> causes delimitation of integer groups as per the locale) is not in
> >the C standard, and as applied to floats is not even in SUSv2.


>That'd make it off-topic here.


I don't agree. "The group's focus is on how to write portable C code",
which is
exactly what my question is about. Furthermore, I don't see that any
other
group is appropriate. The question is not specific to a particular
compiler, OS,
processor or ABI.

 
Reply With Quote
 
Vladimir S. Oka
Guest
Posts: n/a
 
      04-19-2006
(E-Mail Removed) opined:

By pure chance, I remember I wrote this not long ago...

Please don't snip attribution lines.

>>> On the other hand, it is very useful. I'm wondering how people
>>> check for availability of a version of printf that supports it.

>
>>By reading the documentation of their particular implementation?

>
> I guess you don't ever try to write portable C. I can't read the
> documentation for every C implementation. The idea is to anticipate
> implementations that I don't know about.


You know, you must be right. Now, where's that crystal ball got now!

>>Presumably, people using implementations not supporting this (or who
>>never had use for it, as is my case), won't be familiar with the
>>correct syntax to check for you and tell the results.

>
> Many people have used more than one implementation.


So?

--
"If you want to travel around the world and be invited to speak at a
lot of different places, just write a Unix operating system."
(By Linus Torvalds)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

 
Reply With Quote
 
Aki Tuomi
Guest
Posts: n/a
 
      04-19-2006
(E-Mail Removed) kirjoitti:
>>> The ' (single quote/apostrophe - ASCII 0x27) flag in *printf (which
>>> causes delimitation of integer groups as per the locale) is not in
>>> the C standard, and as applied to floats is not even in SUSv2.

>
>> That'd make it off-topic here.

>
> I don't agree. "The group's focus is on how to write portable C code",
> which is
> exactly what my question is about. Furthermore, I don't see that any
> other
> group is appropriate. The question is not specific to a particular
> compiler, OS,
> processor or ABI.
>


Don't use non-ANSI C then? =)

Aki Tuomi
 
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
64 bit portability, size_t, and printf format strings dank C Programming 5 06-30-2006 12:07 AM
(void) printf vs printf whatluo C Programming 29 09-08-2005 05:42 PM
'#' conversion flag in printf() doesn't work with NULL character Erik Leunissen C Programming 9 02-25-2005 11:32 PM
bus error with printf line included, error without printf line? ben C Programming 4 06-26-2004 04:42 PM
REQ: Extended printf() with word-wrapping column format flag nimdez C Programming 5 08-10-2003 10:53 PM



Advertisments