Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: pmontgom@cwi.nl (Peter L. Montgomery)
Subject: Re: long long in Digital Unix
Date: 1997/08/17	[thread overview]
Message-ID: <EF1zCF.A7r@cwi.nl> (raw)
In-Reply-To: qxpvi152mva.fsf@foobar.cs.colorado.edu


In article <qxpvi152mva.fsf@foobar.cs.colorado.edu> 
Dirk Grunwald <grunwald@foobar.cs.colorado.edu> writes:

>I'm porting a program that makes extensive use of 'long long'
>under Solaris. They intend it to mean 64 bit longs.

>The Digital Unix 'printf' and and 'scanf' don't grok the '%lld'
>specification for a long long value. ANyone know of a way
>around thsi w/o #ifdef'ing all the instances?


    For printf, write your own conversion.  2^63 < 10^19,
so a signed 64-bit integer needs at most a sign,
19 digits and a null terminator.  Then

           typedef char llbuf_t[21];
     
           extern char* llout(long long, llbuf_t);

llout should output its first argument into the buffer
given by the second argument, and return a pointer to the
first character used in the buffer.  If a printf outputs
three long longs n1, n2, n3, then you use


          llbuf_t n1buf, n2buf, n3buf;
          printf("n1 = %s, n2 = %s, n3 = %s\n",
                  llout(n1, n1buf), llout(n2, n2buf), llout(n3, n3buf));

A similar design applies to any user-defined type which
printf does not directly support.

        Scanf is harder.  You can use the %s format with 
a maximum length, to ensure your buffer does not overflow.
Then convert the data yourself.
-- 
        Peter L. Montgomery    pmontgom@cwi.nl    San Rafael, California

A mathematician whose age has doubled since he last drove an automobile.




  parent reply	other threads:[~1997-08-17  4:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-08-17  4:00 long long in Digital Unix Dirk Grunwald
1997-08-17  4:00 ` Arun Sharma
1997-08-17  4:00 ` Peter L. Montgomery [this message]
1997-08-18  4:00 ` Dirk Grunwald
1997-08-20  4:00 ` John Hascall
     [not found]   ` <danpop.872269363@news.cern.ch>
1997-08-24  4:00     ` John Hascall
1997-08-21  4:00 ` Peter Quodling
read-only archive

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