printf() Specification for size_t?

What printf() format specifier will allow me to print a size_t integer?

Seems like it should be there, but couldn't find it in documentation.

I'm using %ul, but that might not work on every system, I think.

Thanks.

--
David T. Ashley              (dta@e3ft.com)
http://www.e3ft.com          (Consulting Home Page)
http://www.dtashley.com      (Personal Home Page)
http://gpl.e3ft.com          (GPL Publications and Projects)
0
dta (455)
2/21/2008 2:51:02 AM
comp.lang.c 29882 articles. 34 followers. spinoza1111 (3247) is leader. Post Follow

13 Replies
122 Views

Similar Articles

[PageSpeed] 56
In article <ZbednabdyeYqeiHanZ2dnUVZ_gydnZ2d@giganews.com>,
David T. Ashley <dta@e3ft.com> wrote:
>What printf() format specifier will allow me to print a size_t integer?
>
>Seems like it should be there, but couldn't find it in documentation.
>
>I'm using %ul, but that might not work on every system, I think.

For C90, cast it to unsigned long and use %lu:
--------
printf("The size_t value is %lu\n",(unsigned long)sz);
--------
If you have C99, use %zu.

Note that %lu and %ul are not the same.


dave

-- 
Dave Vandervies                             dj3vande at eskimo dot com
Interestingly the venom isn't poisonous in the traditional sense, it's
just a very powerful relaxant. You relax to the point where you don't
breath.                --Andrew Nicholson in the scary devil monastery
0
dj3vande3 (264)
2/21/2008 3:12:54 AM
"David T. Ashley" <d...@e3ft.com> wrote:
> What printf() format specifier will allow me to print
> a size_t integer?

Under C90, you should use the largest (portable)
unsigned integer type, namely unsigned long...

  printf("%lu\n", (unsigned long) sizeof x);

Under C99, you can use the length modifier z...

  printf("%zu\n", sizeof x);

> Seems like it should be there, but couldn't find
> it in documentation.
>
> I'm using %ul,

Which will print an unsigned int value followed by an
ell.

> but that might not work on every
> system, I think.

Using unsigned long (uncluding conversion) is reasonably
forwards compatible. That said, it's possible to cater
for both worlds with some conditional includes and macros,
but it generally isn't worth the hassle since it's
relatively rare to print a size_t without knowing limits
on how big the object that it refers to can reasonably
be.

For instance, if you're dealing with objects that might
be larger than 4G, then you're more likely to be printing
the size in megabytes or gigabytes. Either way the integer
calculation is likely to be in the range of an unsigned
long.

--
Peter
0
airia (1802)
2/21/2008 3:24:51 AM
<dj3vande@csclub.uwaterloo.ca.invalid> wrote in message 
news:fpiq7m$6om$1@rumours.uwaterloo.ca...
> In article <ZbednabdyeYqeiHanZ2dnUVZ_gydnZ2d@giganews.com>,
> David T. Ashley <dta@e3ft.com> wrote:
>>What printf() format specifier will allow me to print a size_t integer?
>>
>>Seems like it should be there, but couldn't find it in documentation.
>>
>>I'm using %ul, but that might not work on every system, I think.
>
> For C90, cast it to unsigned long and use %lu:
> --------
> printf("The size_t value is %lu\n",(unsigned long)sz);
> --------
> If you have C99, use %zu.
>
> Note that %lu and %ul are not the same.

I had a brain malfunction.  I actually used %lu, which worked fine, but 
somehow in the newsgroup post I stated "%ul".

I'm aware that on my platform, "lu" works fine (naturally, I looked up the 
size_t definition before I did this).

My only fear (and the reason I made the post) is that I could envision 
platforms where the largest integer has far more bits than the address space 
of the machine.  I've never seen such a thing, but it seems it could exist.

In other words, I can't figure out why size_t _____necessarily_____ has any 
relationship to the largest integer size. 

0
dta (455)
2/21/2008 5:11:28 AM
"Peter Nilsson" <airia@acay.com.au> wrote in message 
news:288c586d-1c48-4afc-94cb-336ecc503bf4@d4g2000prg.googlegroups.com...
> "David T. Ashley" <d...@e3ft.com> wrote:
>> What printf() format specifier will allow me to print
>> a size_t integer?
>
> Using unsigned long (uncluding conversion) is reasonably
> forwards compatible. That said, it's possible to cater
> for both worlds with some conditional includes and macros,
> but it generally isn't worth the hassle since it's
> relatively rare to print a size_t without knowing limits
> on how big the object that it refers to can reasonably
> be.
>
> For instance, if you're dealing with objects that might
> be larger than 4G, then you're more likely to be printing
> the size in megabytes or gigabytes. Either way the integer
> calculation is likely to be in the range of an unsigned
> long.

I had a brain malfunction.  I actually used %lu, which worked fine, but 
somehow in the newsgroup post I stated "%ul".

I'm aware that on my platform, "lu" works fine (naturally, I looked up the 
size_t definition before I did this).

My only fear (and the reason I made the post) is that I could envision 
platforms where the largest integer has far more bits than the address space 
of the machine.  I've never seen such a thing, but it seems it could exist.

In other words, I can't figure out why size_t _____necessarily_____ has any 
relationship to the largest integer size. 

0
dta (455)
2/21/2008 5:12:31 AM
David T. Ashley wrote:
> What printf() format specifier will allow me to print a size_t integer?
> 
> Seems like it should be there, but couldn't find it in documentation.
> 
> I'm using %ul, but that might not work on every system, I think.

"%ul" should never work, while "%lu" often will.

If you have a library supporting the C99 specifier "%zu", use that.
Otherwise, you can't get much safer than
      "%llu" with a cast to (unsigned long long)
If your implementation supports neither, then use
      "%lu" with a cast to (unsigned long)
and pray.

0
mambuhl (2202)
2/21/2008 6:04:55 AM
Martin Ambuhl said:

> David T. Ashley wrote:
>> What printf() format specifier will allow me to print a size_t integer?
>> 
>> Seems like it should be there, but couldn't find it in documentation.
>> 
>> I'm using %ul, but that might not work on every system, I think.
> 
> "%ul" should never work, while "%lu" often will.

I see no reason why %ul should not work. There is nothing to stop 
implementors from using unsigned ints as the underlying type for size_t, 
and there is nothing to stop programmers from putting an 'l' onto stdout 
immediately after the size value.

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
0
rjh (10790)
2/21/2008 8:00:28 AM
"David T. Ashley" <dta@e3ft.com> writes:
> <dj3vande@csclub.uwaterloo.ca.invalid> wrote in message
> news:fpiq7m$6om$1@rumours.uwaterloo.ca...
>> In article <ZbednabdyeYqeiHanZ2dnUVZ_gydnZ2d@giganews.com>,
>> David T. Ashley <dta@e3ft.com> wrote:
>>>What printf() format specifier will allow me to print a size_t integer?
>>>
>>>Seems like it should be there, but couldn't find it in documentation.
>>>
>>>I'm using %ul, but that might not work on every system, I think.
>>
>> For C90, cast it to unsigned long and use %lu:
>> --------
>> printf("The size_t value is %lu\n",(unsigned long)sz);
>> --------
>> If you have C99, use %zu.
>>
>> Note that %lu and %ul are not the same.
>
> I had a brain malfunction.  I actually used %lu, which worked fine,
> but somehow in the newsgroup post I stated "%ul".
>
> I'm aware that on my platform, "lu" works fine (naturally, I looked up
> the size_t definition before I did this).
>
> My only fear (and the reason I made the post) is that I could envision
> platforms where the largest integer has far more bits than the address
> space of the machine.  I've never seen such a thing, but it seems it
> could exist.
>
> In other words, I can't figure out why size_t _____necessarily_____
> has any relationship to the largest integer size. 

size_t is necessarily no bigger than the largest integer size.
There's no guarantee that it's the same as any particular predefined
integer type, which is why (unless you have "%zu") you have to convert
it to some type to print it.

In C90, the largest unsigned integer type (size_t is guaranteed to be
an unsigned type) is unsigned long, so this:

    size_t size = <whatever>;
    printf("size = %lu\n", (unsigned long)size);

should always work.  In C99, unsigned long long isn't guaranteed to be
the widest unsigned integer type (an implementation can provide
extended integer types), and it's conceivable that size_t could be
wider than unsigned long.  It's guaranteed that size_t is no wider
than uintmax_t, but since C99 provides formats for both size_t and
uintmax_t that isn't all that helpful.

If you need portability to both C90 and C99 implementations, you can
still use the "%lu" trick *if* you can guarantee that the particular
value you're printing is no greater than ULONG_MAX.  Even if size_t is
wider than unsigned long, if the value doesn't exceed ULONG_MAX then
the cast performs a (narrowing) conversion that doesn't lose any
information.  (Even if the value is greater than ULONG_MAX, the
semantics of unsigned types means that you'll just get an incorrect
result; there's no undefined behavior.)

If you know your code will run only under conforming C99
implementations, you can use "%zu" (and there's no need for a cast).
But note that, out in the real world, even testing for
__STDC_VERSION__ >= 199901L doesn't necessarily guarantee that "%zu"
will work.  The __STDC_VERSION__ macro is set by the compiler; it's up
to the runtime library to implement printf properly.  An
implementation combining a compiler and a runtime library *should* get
this right, but I think that some don't.

-- 
Keith Thompson (The_Other_Keith) <kst-u@mib.org>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
0
kst-u (21963)
2/21/2008 8:21:28 AM
Richard Heathfield wrote:
> Martin Ambuhl said:
> 
>> David T. Ashley wrote:
>>> What printf() format specifier will allow me to print a size_t integer?
>>>
>>> Seems like it should be there, but couldn't find it in documentation.
>>>
>>> I'm using %ul, but that might not work on every system, I think.
>> "%ul" should never work, while "%lu" often will.
> 
> I see no reason why %ul should not work. There is nothing to stop 
> implementors from using unsigned ints as the underlying type for size_t, 
> and there is nothing to stop programmers from putting an 'l' onto stdout 
> immediately after the size value.

Thank you for your valuable contribution.

0
mambuhl (2202)
2/21/2008 9:14:58 AM
Martin Ambuhl said:

> Richard Heathfield wrote:
>> Martin Ambuhl said:
>> 
>>> David T. Ashley wrote:
>>>> What printf() format specifier will allow me to print a size_t
>>>> integer?
>>>>
>>>> Seems like it should be there, but couldn't find it in documentation.
>>>>
>>>> I'm using %ul, but that might not work on every system, I think.
>>> "%ul" should never work, while "%lu" often will.
>> 
>> I see no reason why %ul should not work. There is nothing to stop
>> implementors from using unsigned ints as the underlying type for size_t,
>> and there is nothing to stop programmers from putting an 'l' onto stdout
>> immediately after the size value.
> 
> Thank you for your valuable contribution.

You're quite welcome, my dear chap!

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
0
rjh (10790)
2/21/2008 10:33:37 AM
Richard Heathfield wrote:
> Martin Ambuhl said:
>> David T. Ashley wrote:
>>
>>> What printf() format specifier will allow me to print a size_t
>>> integer?  Seems like it should be there, but couldn't find it
>>> in documentation.  I'm using %ul, but that might not work on
>>> every system, I think.
>>
>> "%ul" should never work, while "%lu" often will.
> 
> I see no reason why %ul should not work. There is nothing to
> stop implementors from using unsigned ints as the underlying
> type for size_t, and there is nothing to stop programmers from
> putting an 'l' onto stdout immediately after the size value.

I think this will create great confusion for newbies.  It should be
labelled, etc. to attempt to avoid being taken too seriously.

-- 
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: <http://cbfalconer.home.att.net>
            Try the download section.



-- 
Posted via a free Usenet account from http://www.teranews.com

0
cbfalconer (19194)
2/21/2008 1:53:54 PM
On Feb 21, 3:53 pm, CBFalconer <cbfalco...@yahoo.com> wrote:
> Richard Heathfield wrote:
> > Martin Ambuhl said:
> >> David T. Ashley wrote:
>
> >>> What printf() format specifier will allow me to print a size_t
> >>> integer?  Seems like it should be there, but couldn't find it
> >>> in documentation.  I'm using %ul, but that might not work on
> >>> every system, I think.
>
> >> "%ul" should never work, while "%lu" often will.
>
> > I see no reason why %ul should not work. There is nothing to
> > stop implementors from using unsigned ints as the underlying
> > type for size_t, and there is nothing to stop programmers from
> > putting an 'l' onto stdout immediately after the size value.
>
> I think this will create great confusion for newbies.  It should be
> labelled, etc. to attempt to avoid being taken too seriously.
It would also confuse a newbie to think that %ul would print an
unsigned long.
When printf() encounters a % in the string literal, it searches for
one of the conversion specifiers, which are
d,i,a,u,x,X,f,F,e,E,g,G,a,A,c,s,p,n,%, and also parses any flag
characters, length modifiers, precision and field width which are
optional.
When not doing that, printf() simply puts the bytes to stdout.
So, according to that, %ul would be parsed as:
%: start parsing
u: valid conversion specifier. stop parsing
l: byte. put (write) to stdout

Hope this clears any confusion a newbie might had.

Reference: 7.19.6.1 ISO C99
0
vippstar (1211)
2/21/2008 3:10:18 PM
On 21 Feb 2008 at 10:33, Richard Heathfield wrote:
> Martin Ambuhl said:
>
>> Richard Heathfield wrote:
>>> Martin Ambuhl said:
>>> 
>>>> David T. Ashley wrote:
>>>>> What printf() format specifier will allow me to print a size_t
>>>>> integer?
>>>>>
>>>>> Seems like it should be there, but couldn't find it in documentation.
>>>>>
>>>>> I'm using %ul, but that might not work on every system, I think.
>>>> "%ul" should never work, while "%lu" often will.
>>> 
>>> I see no reason why %ul should not work. There is nothing to stop
>>> implementors from using unsigned ints as the underlying type for size_t,
>>> and there is nothing to stop programmers from putting an 'l' onto stdout
>>> immediately after the size value.
>> 
>> Thank you for your valuable contribution.
>
> You're quite welcome, my dear chap!

Ouch! Twice the sarcasm cuts like a knife as we one again play "clc
regulars eating their own"...

0
nospam59 (11087)
2/21/2008 6:38:41 PM
David T. Ashley wrote:
> 
> <dj3vande@csclub.uwaterloo.ca.invalid> wrote in message
> news:fpiq7m$6om$1@rumours.uwaterloo.ca...
> > In article <ZbednabdyeYqeiHanZ2dnUVZ_gydnZ2d@giganews.com>,
> > David T. Ashley <dta@e3ft.com> wrote:
> >>What printf() format specifier
> >>will allow me to print a size_t integer?
> >>
> >>Seems like it should be there,
> >>but couldn't find it in documentation.
> >>
> >>I'm using %ul, but that might not work on every system, I think.
> >
> > For C90, cast it to unsigned long and use %lu:
> > --------
> > printf("The size_t value is %lu\n",(unsigned long)sz);
> > --------
> > If you have C99, use %zu.
> >
> > Note that %lu and %ul are not the same.
> 
> I had a brain malfunction.
> I actually used %lu, which worked fine, but
> somehow in the newsgroup post I stated "%ul".

That's why I call it (long unsigned) instead of (unsigned long).

-- 
pete
0
pfiland (6614)
2/21/2008 9:40:46 PM
Reply:
Similar Artilces:

let's suppress in the light of the specific nights, but don't explode the precise lemons
Cybernetic control of society. Everything on-line and monitored in real-time. : From: "EPIC-News" <epic-news@epic.org> : Date: 05 Jun 1997 19:01:58 -0400 : Subject: EPIC: Clinton Endorses Privacy Rights : : In a commencement address at Morgan State University on May 18, : President Clinton called privacy "one of our most cherished freedoms" : and said that technology should not "break down the wall of privacy and : autonomy free citizens are guaranteed in a free society." Is President Clinton being honest? He supports Cl...

printf rounding
The standard specifies that printf "rounds the value to the appropiate number of digits". This rounding is round to the nearest or something else? Is this rounding affected by the rounding mode? I have implemented rounding to the nearest, but now I am not so sure. Should I use the current rounding mode of the machine? Where is the precise type of rounding of printf specified in the standard? Thanks in advance and sorry if this is a stupid question. jacob Le 01/06/2015 11:30, jacob navia a écrit : > The standard specifies that printf "rounds the ...

strange use of format specifier in printf
Here in this thread http://groups.google.co.in/group/comp.lang.c/browse_frm/thread/c16d280238a95c9/e3b0dbf76f3e02e3?q=finding+endianness&rnum=1#e3b0dbf76f3e02e3 Tydr Schnubbis in 3rd reply used %d for printing char's...isn't it wrong? Money wrote: > Here in this thread > http://groups.google.co.in/group/comp.lang.c/browse_frm/thread/c16d280238a95c9/e3b0dbf76f3e02e3?q=finding+endianness&rnum=1#e3b0dbf76f3e02e3 > > Tydr Schnubbis in 3rd reply used %d for printing char's...isn't it > wrong? No. It will print them in decimal though, not as characters. ...

printf( )
int a=10; printf("%d") the output is 10 int a=10,b=20; printf("%d ") the output is 20 how did it return the last defined variable? why does printf( ) works from right to left? sarma wrote: > int a=10; > printf("%d") Undefined behaviour (expected argument value missing). [Some compilers - eg gcc - can spot this.] > the output is 10 Sheer accident of implementation. (The assigned value has probably leaked into the argument register/location which printf looks at for the first %-inserted value.) > int a=10,b=20; > printf("%d &qu...

Age specific death rates to Life Expectancy
Hi all, I can calculate age specific death rates for about ten years of population data and I need to get to Life expectancy (at age 0 and age 65). What's the best way to go about this in SAS? L_B WINXP SASV9.1 "The beggar laughs in the face of the thief" _________________________________________________________________ Movie session times on Messenger - add Movie Scout today! http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=785&referral=hotmailtagline0707&URL=http://www.yourmovies.com.au/messenger/signup/ Definitely NOT my areas of expertise, but...

some strange printf fuction in C programming...
Hi, I found some strange printf fuction in C programming... what does following means? printf("\033[H\033[J"); ==>what does that mean? fflush(stdout); printf("\033[?25h"); ==>what does that mean? fflush(stdout); Have a nice day. On Wed, 1 Nov 2006 21:35:14 +0900, somez72 <rambo88@gmail.com> wrote: > Hi, > I found some strange printf fuction in C programming... > what does following means? > > printf("\033[H\033[J"); ==>what does that mean? > ...

Extracting printf(...) from (void) printf(....)
HI all How to search for (void) from the line. ex: (void) printf(....) I want to search if (void) is there at the beggining of the line.. if exist then extract printf(....) function. Please let me know how it can be done or tell me the reference so that I can try. Thanks & Regards Gururaja On Feb 2, 9:04 am, guru <guru.nav...@gmail.com> wrote: > HI all > > How to search for (void) from the line. > > ex: (void) printf(....) > > I want to search if (void) is there at the beggining of the line.. if > exist then extract printf(....) function. > > Plea...

question about printf in multithread daemon app ?
Version: 5.5.1 host: windows xp sp2, suse linux enterprise server 9 sp2 compiler: vs.net 2003, gcc 3.3.3 My app runs ok before it is made a daemon app. it always exits after running for a time after it is made a daemon app. In my app, I call printf to print debug info in many threads. I guess because printf is not thread-safe or because printf is not supported by daemon app, so I comment all of the printf calls and the daemon app runs well. so my question is : in daemon all, can printf call in many threads without synch lock cause the app exit ? thanks! Hi, >Ver...

US-TX-Austin: Business Analyst, Writing automation system specifications, workin (45293657616)
US-TX-Austin: Business Analyst, Writing automation system specifications, workin (45293657616) ============================================================================================== Position: Business Analyst Reference: JGG00084 Location: Austin TX Duration: Skills: Writing automation system specifications. Access, SAS, SPSS, Excel, QLP, Business Objects or comparable software. Knowledge of capabilities and limitations of computer systems and ability to troubleshoot computer output errors. ...

printf()-like macro in C90
I want to have debugging macro or function that I can use like: DEBUG("bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4); just as with printf. I want to avoid implementing this functionality myself with varargs etc. Now, in my case, I cannot use printf etc to output with. I have to use some other function that can only take a string. Let's call it output(char* str). Today, when debugging, I insert something like: { char buffer[200]; sprintf(buffer, "bla bla bla %d bla %s bla bla %d %d", 1, "42", 3, 4); output(buffer); } This is te...

Placing variables at a specific location (address) using microblaze GCC
Hello, I am trying to figure out the ins and outs of the MB-GCC compiler. I am not familiar with how to place variable at specific locations in memory. I have used the #pragma directive with other compilers to nail down variables to specific locations in memory. Any help would be appreciated. I think that it may also be neccessary to create another section in memory using the linker. ie .text or .bss etc. Thanks in adavance. Jeremy Specify a new section for your variables, and add this section to your linker script with the fixed address. E.g.: int fixed_data __attribute__ ((section (&q...

Any Mac OS X-specific GUI Samba config tools?
Hi, It's come to my attention that the SSP project (http://xamba.sourceforge.net/ssp/) has been abandoned, and doesn't work properly with Mac OS X Panther. (This project provided Mac OS X-specific GUI configuration tools for Samba.) I'm well aware of cross-platform tools, such as SWAT and Webmin, but I was wondering if there are any OS X-specific GUI Samba configuration tools other than SSP and the very minimal tools that come with Mac OS X? (FWIW, this isn't for me personally; it's for a book I'm writing. I'd like to be able to reference such a tool if i...

Format in PRINTF
Hi, I have a stringarray containing numbers and letters and want to print this string to a file. each line should consist of 130 arrayelements, each element should take two places. Using this format command: format='(130(A2))' just writes the letters, but not the numbers. Anybody an idea??? Thanks a lot corinne coco wrote: > Hi, > > I have a stringarray containing numbers and letters and want to print > this string to a file. each line should consist of 130 arrayelements, > each element should take two places. > > Using this format command: format='(...

Loading specific lines of text
Good day; I am attempting to use the following command to load a text file: >fid=fopen([Dir_Files FN],'r'); >A=textscan(fid, '%3f%4f%2f%1c%6f%6f%4f%6f%1c%7f%1c', 'headerlines',1,... > 'delimiter',' ','multipleDelimsAsOne',1); >fclose(fid) My trouble is that I ONLY require lines from files (and there are 96 files with many many lines in each file) that have the letter "A" as the 10th character. Here is a sample couple of lines from one file: 291200001A41002 0001010050321652N0751206W37856-010 15362000038 ...

wxMac wxString::Printf truncation problem
------_=_NextPart_001_01C5F50A.BA84294E Content-Type: text/plain I've just found a bazaar problem with the wxString::Printf function. It seems to be truncating all (output) strings at 1023 bytes. Being of an ominous number I stepped into the framework and found that the BSD vsnprintf function is not acting as expected. This version of vsnprintf returns the number of bytes that should have been written regardless of the byte limit passed. wxWidgets does expect this BUT it also expects errno to be EOVERFLOW - which it isn't. I'm running 10.4.3, using XCode...

General and specific CM
I have a view on the "whole" CM area I'd like to try on you: (OK, I know this is a software CM "only" newsgroup, but I couldn't find any "general" CM group) I've come to discuss Configuration Management with my co-worker by dividing it into subcategories. Although I'm not a CM myself, I've worked closely with "them" at different companies and feel I have some grasp of the concepts. Let's get on to my view then, shall we? Configuration Management This is the general field, where policies on what to manage, how t...

Is the Single Unix Specification Irrelevant?
I just discovered the Single Unix Specification (version 3) at www.unix.org. In view of the rapid evolution of operating systems in general now, is this spec relevant to Linux and *BSD systems? Thanks, Dave Feustel -- Using ( X | KDE ) with OpenBSD? See Dave's OpenBSD | X | KDE corner at http://dfeustel.home.mindspring.com !!! On 2006-05-27, dfeustel@mindspring.com <dfeustel@mindspring.com> wrote: > I just discovered the Single Unix Specification (version 3) at > www.unix.org. In view of the rapid evolution of operating systems > in general now, is this spe...

use printf
Hi all. I've got an output of 20 numbers, but I wanno print the first 9 number with the two digits decimal operator. I'v egot 1,2,3,4,5,6,7,8 and 9.. but I need 01,02,03,04... I use printf echo `printf '%d\n'`9 -> 09 this is ok but I don't want 010 if I type 10 echo `printf '%d\n'`10 -> 010 Is there another way to do this? really thanx >> On 9 Jul 2006 05:52:29 -0700, >> "Davide" <davide.papagno@gmail.com> said: > Hi all. I've got an output of 20 numbers, but I wanno > print the first 9 number with the two digits...

atomic printf()? (FILE and multiple process)
AFAIK, when a parent and a child share a open file, if both processes try to write some message using write(2), the two strings are not intermixed. I mean, inside of write(2), the output operation will not be interfered by another write(2) on the shared file object. Right? What if both process try to printf(3) into the shared FILE * object instead of write(2)?. Can I expect printf(3) also atomic? (By atomic, I mean among multiple process that share a open file.) If each process calls write(2) twice, the order of 4 write(2) calls are not guaranteed. AFAIK, this is why writev(2) exists. Rig...

printf #5
#include<stdio.h> void main() { printf("%d %d %d %d "); } whats the output and why !!!!!!!!!!!!!!!!!!!!!! dharmesh.gohil02@gmail.com wrote: > #include<stdio.h> > void main() > { > printf("%d %d %d %d "); > } > whats the output and why !!!!!!!!!!!!!!!!!!!!!! > Garbage because it is undefined. -- Ian Collins. dharmesh.gohil02@gmail.com wrote: > > #include<stdio.h> > void main() > { > printf("%d %d %d %d "); > } > whats the output and why !!!!!!!!!!!!!!!!!!!!!! If reformats your hard drive, and conta...

%% in printf
I hope this is not a FAQ. printf("%%%%"); What is the output for this? Is it implementation dependent? TIA. -- main(){char s[37]="CSbwjAjocpy/mw!PS!sbwjAeftqbnnfe/dpn"; int i;for(i=0;i<36;putchar(s[i++]-1));return 0;} On Sun, 09 Nov 2003 23:22:55 +0530, Ravi wrote: > I hope this is not a FAQ. > > printf("%%%%"); > > What is the output for this? "%%%%" >Is it implementation dependent? no, AFAIK On Mon, 10 Nov 2003 05:08:27 +1100, ASiF wrote: >> What is the output for this? > > "%%%%" sry typo o...

ODMG specification
Can anyone point to me where can I get specification of ODL of ODMG ? Especially on how to create a new type ? Many Thanks In advance ...

printf "fails" in extension
I'm trying to "extend" Python by writing a bit of C code. I followed the example in the Python documentation, and almost everything works fine. I can build a DLL, fire up an interactive Python session and import my new module. Methods work almost as expected. The only problem I'm having is that I can't print to the screen from the C code. Printing to a file works fine, but neither printf nor fprintf(stdout,...) puts anything onto the screen. I'm working in Windows2K, using Python2.3. Is there some trick to get this to work? I'm wondering if this is a compil...

UTF-8 and printf
Hello, I'm trying to use printf to give a tabulated format to my output, like for example: printf "%20s %10s %10s", title, author, date being title, author and date string variables. The text contained in these variables is uft-8 encoded, and this makes printf to misalign the outupt. The reason is that one multi-byte char (for example, a two- byte char) is counted as several chars (two chars), and thus the number of spaces required for padding is wrongly calculated. I searched for discussions about ruby and utf8, and in general it does not appear as an easy issue. I read abou...

Clipping does not work properly with ATI specific card.
I have a little problem in the following case. Please let me know if you have any solutions or informations. Using glClipPlane, I am trying to create and draw section edges to a target polygons with glPolygonMode( GL_LINE ). According to MSDN library/Clipping explanation, "For polygons, an entire edge may need to be constructed between new vertices generated at the clip points." ms-help://MS.MSDNQTR.2003FEB.1041/opengl/over02_2zc7.htm This is true because I maked sure it using both GL_FILL and GL_LINE polygon modes. But it seems that some ATI graphics card do not re-constructe...