* long long in Digital Unix
@ 1997-08-17 4:00 Dirk Grunwald
1997-08-17 4:00 ` Arun Sharma
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Dirk Grunwald @ 1997-08-17 4:00 UTC (permalink / raw)
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?
--
Dirk Grunwald Assoc. Prof, Univ. of Colorado at Boulder
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: long long in Digital Unix
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
1997-08-18 4:00 ` Dirk Grunwald
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Peter L. Montgomery @ 1997-08-17 4:00 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: long long in Digital Unix
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
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Arun Sharma @ 1997-08-17 4:00 UTC (permalink / raw)
On 17 Aug 1997 03:13:29 -0600, Dirk Grunwald wrote:
d> I'm porting a program that makes extensive use of 'long
d> long' under Solaris. They intend it to mean 64 bit longs.
d> The Digital Unix 'printf' and and 'scanf' don't grok the
d> '%lld' specification for a long long value. ANyone know of
d> a way around thsi w/o #ifdef'ing all the instances?
How about linking in a wrapper around printf, which handles the OS
specific stuff ? That way, you'll have the complexity moved to the
*definition* of printf, rather than the use.
-Arun
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: long long in Digital Unix
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
@ 1997-08-18 4:00 ` Dirk Grunwald
1997-08-20 4:00 ` John Hascall
1997-08-21 4:00 ` Peter Quodling
4 siblings, 0 replies; 7+ messages in thread
From: Dirk Grunwald @ 1997-08-18 4:00 UTC (permalink / raw)
The problem is that the program uses '%lld' to specify the printing of
a 'long long', or the scanning of a long long.
Someone suggested writing a converter that would check & convert the
strings on the fly. E.g,
fprintf(stderr,CleanMeUp("i always say woof a%lld ay log"), my_data)
Another alternative is to use pre-processoror string concatenation.
Yet another was to link with the Gnu libc routines, which correctly handle this case.
--
Dirk Grunwald Assoc. Prof, Univ. of Colorado at Boulder
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: long long in Digital Unix
1997-08-17 4:00 long long in Digital Unix Dirk Grunwald
` (2 preceding siblings ...)
1997-08-18 4:00 ` Dirk Grunwald
@ 1997-08-20 4:00 ` John Hascall
[not found] ` <danpop.872269363@news.cern.ch>
1997-08-21 4:00 ` Peter Quodling
4 siblings, 1 reply; 7+ messages in thread
From: John Hascall @ 1997-08-20 4:00 UTC (permalink / raw)
Dirk Grunwald <grunwald@foobar.cs.colorado.edu> wrote:
}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?
sed 's/%lld/%ld/g' < bogus.c > sane.c ??
John
--
John Hascall, Software Engr. Shut up, be happy. The conveniences you
ISU Computation Center demanded are now mandatory. -Jello Biafra
mailto:john@iastate.edu
http://www.cc.iastate.edu/staff/systems/john/welcome.html <-- the usual crud
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: long long in Digital Unix
1997-08-17 4:00 long long in Digital Unix Dirk Grunwald
` (3 preceding siblings ...)
1997-08-20 4:00 ` John Hascall
@ 1997-08-21 4:00 ` Peter Quodling
4 siblings, 0 replies; 7+ messages in thread
From: Peter Quodling @ 1997-08-21 4:00 UTC (permalink / raw)
Dirk Grunwald wrote:
>
> 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?
>
> --
> Dirk Grunwald Assoc. Prof, Univ. of Colorado at Boulder
In NeoMelanesian Pidgin, the Lingua Franca of Papua New Guinea, "long
long" translates
to "idiot".
This struck me as being particularly relavent to C and Unix.
Peter Q
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: long long in Digital Unix
[not found] ` <danpop.872269363@news.cern.ch>
@ 1997-08-24 4:00 ` John Hascall
0 siblings, 0 replies; 7+ messages in thread
From: John Hascall @ 1997-08-24 4:00 UTC (permalink / raw)
Dan Pop <Dan.Pop@cern.ch> wrote:
}john@iastate.edu (John Hascall) writes:
}>Dirk Grunwald <grunwald@foobar.cs.colorado.edu> wrote:
}>}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?
}> sed 's/%lld/%ld/g' < bogus.c > sane.c ??
}You can go one step further and really sanitize the code:
} sed 's/%lld/%ld/g' < bogus.c | sed 's/long long/long/g' > sane.c
Watch for:
long longvar;
though :)
John
--
John Hascall, Software Engr. Shut up, be happy. The conveniences you
ISU Computation Center demanded are now mandatory. -Jello Biafra
mailto:john@iastate.edu
http://www.cc.iastate.edu/staff/systems/john/welcome.html <-- the usual crud
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1997-08-24 4:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox