unsigned long long | | |
Is the unsigned long long primitive data type supported in ANSI
standard C?
I've tried using it a couple of times in standard C, but to no avail.
I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
with RedHat linux 9.
If not, what data type will yield the largest unsigned integer for me?
Thanks for your help,
Rich | | | | re: unsigned long long
Richard A. Huebner <encprof@yahoo.com> scribbled the following:[color=blue]
> Is the unsigned long long primitive data type supported in ANSI
> standard C?[/color]
In C99, yes. In C90, no. Most current implementations of ANSI standard
C are still C90.
[color=blue]
> I've tried using it a couple of times in standard C, but to no avail.
> I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
> with RedHat linux 9.[/color]
[color=blue]
> If not, what data type will yield the largest unsigned integer for me?[/color]
unsigned long.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery | | | | re: unsigned long long
"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
news:borl51$lbd$1@oravannahka.helsinki.fi...[color=blue][color=green]
> > I've tried using it a couple of times in standard C, but to no avail.
> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
> > with RedHat linux 9.[/color]
>[color=green]
> > If not, what data type will yield the largest unsigned integer for me?[/color]
>
> unsigned long.[/color]
Actually GCC has supported "unsigned long long" for quite some time. MSVC
supports "unsigned __int64" which is a 64-bit type..
Tom | | | | re: unsigned long long
Richard A. Huebner wrote:[color=blue]
> If not, what data type will yield the largest unsigned integer
> for me?[/color]
I don't know how to answer your question.
uint64_t might be useful still? | | | | re: unsigned long long
Tom St Denis <tomstdenis@iahu.ca> scribbled the following:[color=blue]
> "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> news:borl51$lbd$1@oravannahka.helsinki.fi...[color=green][color=darkred]
>> > I've tried using it a couple of times in standard C, but to no avail.
>> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
>> > with RedHat linux 9.[/color]
>>[color=darkred]
>> > If not, what data type will yield the largest unsigned integer for me?[/color]
>>
>> unsigned long.[/color][/color]
[color=blue]
> Actually GCC has supported "unsigned long long" for quite some time. MSVC
> supports "unsigned __int64" which is a 64-bit type..[/color]
Yes, but hardly in ANSI standard C, or what?
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Immanuel Kant but Genghis Khan."
- The Official Graffitist's Handbook | | | | re: unsigned long long
"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
news:borm04$lnc$1@oravannahka.helsinki.fi...[color=blue]
> Tom St Denis <tomstdenis@iahu.ca> scribbled the following:[color=green]
> > "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> > news:borl51$lbd$1@oravannahka.helsinki.fi...[color=darkred]
> >> > I've tried using it a couple of times in standard C, but to no avail.
> >> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that[/color][/color][/color]
comes[color=blue][color=green][color=darkred]
> >> > with RedHat linux 9.
> >>
> >> > If not, what data type will yield the largest unsigned integer for[/color][/color][/color]
me?[color=blue][color=green][color=darkred]
> >>
> >> unsigned long.[/color][/color]
>[color=green]
> > Actually GCC has supported "unsigned long long" for quite some time.[/color][/color]
MSVC[color=blue][color=green]
> > supports "unsigned __int64" which is a 64-bit type..[/color]
>
> Yes, but hardly in ANSI standard C, or what?[/color]
ANSI is old. I for one welcome our new ISO overlords.
Tom | | | | re: unsigned long long
Tom St Denis <tomstdenis@iahu.ca> scribbled the following:[color=blue]
> "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> news:borm04$lnc$1@oravannahka.helsinki.fi...[color=green]
>> Tom St Denis <tomstdenis@iahu.ca> scribbled the following:[color=darkred]
>> > "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
>> > news:borl51$lbd$1@oravannahka.helsinki.fi...
>> >> > I've tried using it a couple of times in standard C, but to no avail.
>> >> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that[/color][/color]
> comes[color=green][color=darkred]
>> >> > with RedHat linux 9.
>> >>
>> >> > If not, what data type will yield the largest unsigned integer for[/color][/color]
> me?[color=green][color=darkred]
>> >>
>> >> unsigned long.[/color]
>>[color=darkred]
>> > Actually GCC has supported "unsigned long long" for quite some time.[/color][/color]
> MSVC[color=green][color=darkred]
>> > supports "unsigned __int64" which is a 64-bit type..[/color]
>>
>> Yes, but hardly in ANSI standard C, or what?[/color][/color]
[color=blue]
> ANSI is old. I for one welcome our new ISO overlords.[/color]
I would think that the difference between the ANSI and ISO versions of
the C standard is entirely bureaucratic and has no effect on the
technical content.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'So called' means: 'There is a long explanation for this, but I have no
time to explain it here.'"
- JIPsoft | | | | re: unsigned long long
"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
news:bormbg$lut$1@oravannahka.helsinki.fi...[color=blue][color=green]
> > ANSI is old. I for one welcome our new ISO overlords.[/color]
>
> I would think that the difference between the ANSI and ISO versions of
> the C standard is entirely bureaucratic and has no effect on the
> technical content.[/color]
Be that as it may "unsigned long long" is part of ISOC AFAIK.
Tom | | | | re: unsigned long long
Tom St Denis <tomstdenis@iahu.ca> scribbled the following:[color=blue]
> "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> news:bormbg$lut$1@oravannahka.helsinki.fi...[color=green][color=darkred]
>> > ANSI is old. I for one welcome our new ISO overlords.[/color]
>>
>> I would think that the difference between the ANSI and ISO versions of
>> the C standard is entirely bureaucratic and has no effect on the
>> technical content.[/color][/color]
[color=blue]
> Be that as it may "unsigned long long" is part of ISOC AFAIK.[/color]
ISO C99, Tom. Not ISO C90.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon | | | | re: unsigned long long
"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
news:bormg1$lut$2@oravannahka.helsinki.fi...[color=blue]
> Tom St Denis <tomstdenis@iahu.ca> scribbled the following:[color=green]
> > "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> > news:bormbg$lut$1@oravannahka.helsinki.fi...[color=darkred]
> >> > ANSI is old. I for one welcome our new ISO overlords.
> >>
> >> I would think that the difference between the ANSI and ISO versions of
> >> the C standard is entirely bureaucratic and has no effect on the
> >> technical content.[/color][/color]
>[color=green]
> > Be that as it may "unsigned long long" is part of ISOC AFAIK.[/color]
>
> ISO C99, Tom. Not ISO C90.[/color]
Tom assumes we're dealing with the latest not the oldest.
Otherwise crack out some K&R !
Tom | | | | re: unsigned long long
"Tom St Denis" <tomstdenis@iahu.ca> wrote in message
news:P1dsb.2348$iD1.1109@news04.bloor.is.net.cable .rogers.com...
[color=blue]
> "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> news:bormbg$lut$1@oravannahka.helsinki.fi...[color=green][color=darkred]
> > > ANSI is old. I for one welcome our new ISO overlords.[/color]
> >
> > I would think that the difference between the ANSI and ISO versions of
> > the C standard is entirely bureaucratic and has no effect on the
> > technical content.[/color]
>
> Be that as it may "unsigned long long" is part of ISOC AFAIK.[/color]
The current ANSI standard for C is identical to the current ISO
standard for C, aka C99.
P.J. Plauger
Dinkumware, Ltd. http://www.dinkumware.com | | | | re: unsigned long long
Richard A. Huebner wrote:[color=blue]
>
> Is the unsigned long long primitive data type supported in ANSI
> standard C?
>
> I've tried using it a couple of times in standard C, but to no avail.
> I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
> with RedHat linux 9.
>
> If not, what data type will yield the largest unsigned integer for me?
>
> Thanks for your help,
>
> Rich[/color]
Try this.
/*
Sizes of various things in bits..
*/
#include <stdio.h>
#include <limits.h>
int main(void) {
unsigned int a, b, c;
unsigned long long x, y, z;
c = -1;
b = 1 << (sizeof(int)*CHAR_BIT-1);
a = ~b;
z = -1;
y = 1LL << (sizeof(long long)*CHAR_BIT-1);
x = ~y;
printf("Size of void = %2lu bits\n", sizeof(void) *
CHAR_BIT);
printf("Size of char = %2lu bits\n", sizeof(char) *
CHAR_BIT);
printf("Size of short = %2lu bits\n", sizeof(short) *
CHAR_BIT);
printf("Size of int = %2lu bits\n", sizeof(int) *
CHAR_BIT);
printf("Size of long = %2lu bits\n", sizeof(long) *
CHAR_BIT);
printf("Size of long long = %2lu bits\n", sizeof(long long) *
CHAR_BIT);
printf("Size of int * = %2lu bits\n", sizeof(int *) *
CHAR_BIT);
printf("Size of char * = %2lu bits\n", sizeof(char *) *
CHAR_BIT);
printf("Size of void * = %2lu bits\n", sizeof(void *) *
CHAR_BIT);
printf("Size of float = %2lu bits\n", sizeof(float) *
CHAR_BIT);
printf("Size of double = %2lu bits\n", sizeof(double) *
CHAR_BIT);
printf("Size of long double = %2lu bits\n", sizeof(long double) *
CHAR_BIT);
printf("Max int = %11d\n", a);
printf("Min int = %11d\n", b);
printf("Max unsigned int = %11u\n", c);
printf("Max long long = %20lld\n", x);
printf("Min long long = %20lld\n", y);
printf("Max unsigned long long = %20llu\n", z);
return 0;
}
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- | | | | re: unsigned long long
Joe Wright wrote:[color=blue]
>
> Richard A. Huebner wrote:[color=green]
> >
> > Is the unsigned long long primitive data type supported in ANSI
> > standard C?
> >
> > I've tried using it a couple of times in standard C, but to no avail.
> > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
> > with RedHat linux 9.
> >
> > If not, what data type will yield the largest unsigned integer for me?
> >
> > Thanks for your help,
> >
> > Rich[/color]
>
> Try this.
> [code snipped; see up-thread][/color]
I tried it, and the compiler said:
"foo.c", line 12: warning: integer overflow detected: op "<<"
"foo.c", line 19: cannot take sizeof void
cc: acomp failed for foo.c
--
Eric.Sosman@sun.com | | | | re: unsigned long long
Joe Wright wrote:
<snip>
[color=blue]
> printf("Size of char = %2lu bits\n", sizeof(char) *
> CHAR_BIT);[/color]
Apart from Eric's comments, you may find it a good idea to cast the
expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
variadic function such as printf.
--
Richard Heathfield : binary@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton | | | | re: unsigned long long
Eric Sosman wrote:[color=blue]
>
> Joe Wright wrote:[color=green]
> >
> > Richard A. Huebner wrote:[color=darkred]
> > >
> > > Is the unsigned long long primitive data type supported in ANSI
> > > standard C?
> > >
> > > I've tried using it a couple of times in standard C, but to no avail.
> > > I'm using both MS VIsual C++ 6, as well as the gcc compiler that comes
> > > with RedHat linux 9.
> > >
> > > If not, what data type will yield the largest unsigned integer for me?
> > >
> > > Thanks for your help,
> > >
> > > Rich[/color]
> >
> > Try this.
> > [code snipped; see up-thread][/color]
>
> I tried it, and the compiler said:
>
> "foo.c", line 12: warning: integer overflow detected: op "<<"
> "foo.c", line 19: cannot take sizeof void
> cc: acomp failed for foo.c
>[/color]
What was wrong? Should ..
y = 1LL << (sizeof(long long)*CHAR_BIT-1);
be
y = 1ULL << (sizeof(long long)*CHAR_BIT-1);
or something?
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- | | | | re: unsigned long long
Richard Heathfield wrote:[color=blue]
>
> Joe Wright wrote:
>
> <snip>
>[color=green]
> > printf("Size of char = %2lu bits\n", sizeof(char) *
> > CHAR_BIT);[/color]
>
> Apart from Eric's comments, you may find it a good idea to cast the
> expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
> variadic function such as printf.
>[/color]
Hmm.. size_t is unsigned long on my system. But I guess we're not
supposed to know that.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- | | | | re: unsigned long long
In <bosba5$s39$3@sparta.btinternet.com> Richard Heathfield <dontmail@address.co.uk.invalid> writes:
[color=blue]
>Joe Wright wrote:
>
><snip>
>[color=green]
>> printf("Size of char = %2lu bits\n", sizeof(char) *
>> CHAR_BIT);[/color]
>
>Apart from Eric's comments, you may find it a good idea to cast the
>expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
>variadic function such as printf.[/color]
Or, more generally, to the actual type expected by the respective
conversion description.
Unless you're using a conforming C99 implementation, there is no
conversion description that is guarantee to properly handle a size_t
value. Even worse, in the case of sizeof(type) * CHAR_BIT, the type
of the expression can be either size_t or int.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de | | | | re: unsigned long long
In <3FB16B89.37DD@earthlink.net> Joe Wright <joewwright@earthlink.net> writes:
[color=blue]
>Try this.
>
>/*
> Sizes of various things in bits..
>*/
>#include <stdio.h>
>#include <limits.h>
>
>int main(void) {
> unsigned int a, b, c;
> unsigned long long x, y, z;
>
> c = -1;
> b = 1 << (sizeof(int)*CHAR_BIT-1);
> a = ~b;
>
> z = -1;
> y = 1LL << (sizeof(long long)*CHAR_BIT-1);
> x = ~y;
>
> printf("Size of void = %2lu bits\n", sizeof(void) *
>CHAR_BIT);
> printf("Size of char = %2lu bits\n", sizeof(char) *
>CHAR_BIT);
> printf("Size of short = %2lu bits\n", sizeof(short) *
>CHAR_BIT);
> printf("Size of int = %2lu bits\n", sizeof(int) *
>CHAR_BIT);
> printf("Size of long = %2lu bits\n", sizeof(long) *
>CHAR_BIT);
> printf("Size of long long = %2lu bits\n", sizeof(long long) *
>CHAR_BIT);
> printf("Size of int * = %2lu bits\n", sizeof(int *) *
>CHAR_BIT);
> printf("Size of char * = %2lu bits\n", sizeof(char *) *
>CHAR_BIT);
> printf("Size of void * = %2lu bits\n", sizeof(void *) *
>CHAR_BIT);
> printf("Size of float = %2lu bits\n", sizeof(float) *
>CHAR_BIT);
> printf("Size of double = %2lu bits\n", sizeof(double) *
>CHAR_BIT);
> printf("Size of long double = %2lu bits\n", sizeof(long double) *
>CHAR_BIT);
> printf("Max int = %11d\n", a);
> printf("Min int = %11d\n", b);
> printf("Max unsigned int = %11u\n", c);
> printf("Max long long = %20lld\n", x);
> printf("Min long long = %20lld\n", y);
> printf("Max unsigned long long = %20llu\n", z);
> return 0;
>}[/color]
Try it yourself, with the compiler in conforming mode, this time!
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de | | | | re: unsigned long long
In <z4dsb.2350$iD1.1236@news04.bloor.is.net.cable.rog ers.com> "Tom St Denis" <tomstdenis@iahu.ca> writes:
[color=blue]
>"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
>news:bormg1$lut$2@oravannahka.helsinki.fi...[color=green]
>> Tom St Denis <tomstdenis@iahu.ca> scribbled the following:[color=darkred]
>> > "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
>> > news:bormbg$lut$1@oravannahka.helsinki.fi...
>> >> > ANSI is old. I for one welcome our new ISO overlords.
>> >>
>> >> I would think that the difference between the ANSI and ISO versions of
>> >> the C standard is entirely bureaucratic and has no effect on the
>> >> technical content.[/color]
>>[color=darkred]
>> > Be that as it may "unsigned long long" is part of ISOC AFAIK.[/color]
>>
>> ISO C99, Tom. Not ISO C90.[/color]
>
>Tom assumes we're dealing with the latest not the oldest.[/color]
An excellent illustration of the point I've made in another thread.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de | | | | re: unsigned long long
In <3FB2246F.4D14@earthlink.net> Joe Wright <joewwright@earthlink.net> writes:
[color=blue]
>Richard Heathfield wrote:[color=green]
>>
>> Joe Wright wrote:
>>
>> <snip>
>>[color=darkred]
>> > printf("Size of char = %2lu bits\n", sizeof(char) *
>> > CHAR_BIT);[/color]
>>
>> Apart from Eric's comments, you may find it a good idea to cast the
>> expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
>> variadic function such as printf.
>>[/color]
>Hmm.. size_t is unsigned long on my system. But I guess we're not
>supposed to know that.[/color]
Even if you know that, do you also know what is size_t on the systems of
the people trying to use your program?
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de | | | | re: unsigned long long
"Dan Pop" <Dan.Pop@cern.ch> wrote in message
news:botdtu$ndv$9@sunnews.cern.ch...[color=blue]
> In <z4dsb.2350$iD1.1236@news04.bloor.is.net.cable.rog ers.com> "Tom St[/color]
Denis" <tomstdenis@iahu.ca> writes:[color=blue]
>
>[color=green]
> >"Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> >news:bormg1$lut$2@oravannahka.helsinki.fi...[color=darkred]
> >> Tom St Denis <tomstdenis@iahu.ca> scribbled the following:
> >> > "Joona I Palaste" <palaste@cc.helsinki.fi> wrote in message
> >> > news:bormbg$lut$1@oravannahka.helsinki.fi...
> >> >> > ANSI is old. I for one welcome our new ISO overlords.
> >> >>
> >> >> I would think that the difference between the ANSI and ISO versions[/color][/color][/color]
of[color=blue][color=green][color=darkred]
> >> >> the C standard is entirely bureaucratic and has no effect on the
> >> >> technical content.
> >>
> >> > Be that as it may "unsigned long long" is part of ISOC AFAIK.
> >>
> >> ISO C99, Tom. Not ISO C90.[/color]
> >
> >Tom assumes we're dealing with the latest not the oldest.[/color]
>
> An excellent illustration of the point I've made in another thread.[/color]
Tom von Tom has ways of making you talk!
Tom | | | | re: unsigned long long
Get your Server or Homepage now
Choose which one you prefer.
Redhat, Debian, FreeBSD, Mandrake, Windows, SUSE http://www.comserver.net | | | | re: unsigned long long
Jonathan2s6 <jonathan2s6@aol.com> scribbled the following:[color=blue]
> Get your Server or Homepage now[/color]
[color=blue]
> Choose which one you prefer.
> Redhat, Debian, FreeBSD, Mandrake, Windows, SUSE[/color]
Get lost.
--
/-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"A bee could, in effect, gather its junk. Llamas (no poor quadripeds) tune
and vow excitedly zooming."
- JIPsoft | | | | re: unsigned long long
Dan Pop wrote:[color=blue]
>
> In <3FB16B89.37DD@earthlink.net> Joe Wright <joewwright@earthlink.net> writes:
>[color=green]
> >Try this.
> >
> >/*
> > Sizes of various things in bits..
> >*/
> >#include <stdio.h>
> >#include <limits.h>
> >
> >int main(void) {
> > unsigned int a, b, c;
> > unsigned long long x, y, z;
> >
> > c = -1;
> > b = 1 << (sizeof(int)*CHAR_BIT-1);
> > a = ~b;
> >
> > z = -1;
> > y = 1LL << (sizeof(long long)*CHAR_BIT-1);
> > x = ~y;
> >
> > printf("Size of void = %2lu bits\n", sizeof(void) *
> >CHAR_BIT);
> > printf("Size of char = %2lu bits\n", sizeof(char) *
> >CHAR_BIT);
> > printf("Size of short = %2lu bits\n", sizeof(short) *
> >CHAR_BIT);
> > printf("Size of int = %2lu bits\n", sizeof(int) *
> >CHAR_BIT);
> > printf("Size of long = %2lu bits\n", sizeof(long) *
> >CHAR_BIT);
> > printf("Size of long long = %2lu bits\n", sizeof(long long) *
> >CHAR_BIT);
> > printf("Size of int * = %2lu bits\n", sizeof(int *) *
> >CHAR_BIT);
> > printf("Size of char * = %2lu bits\n", sizeof(char *) *
> >CHAR_BIT);
> > printf("Size of void * = %2lu bits\n", sizeof(void *) *
> >CHAR_BIT);
> > printf("Size of float = %2lu bits\n", sizeof(float) *
> >CHAR_BIT);
> > printf("Size of double = %2lu bits\n", sizeof(double) *
> >CHAR_BIT);
> > printf("Size of long double = %2lu bits\n", sizeof(long double) *
> >CHAR_BIT);
> > printf("Max int = %11d\n", a);
> > printf("Min int = %11d\n", b);
> > printf("Max unsigned int = %11u\n", c);
> > printf("Max long long = %20lld\n", x);
> > printf("Min long long = %20lld\n", y);
> > printf("Max unsigned long long = %20llu\n", z);
> > return 0;
> >}[/color]
>
> Try it yourself, with the compiler in conforming mode, this time!
>[/color]
Come on Dan, lighten up. As you have noted elsethread, we are not likely
to have C99 conformance. Vanilla gcc compiles this fine. With -ansi
-pedantic it complains about 'long long' of course. I've already
forgotten why I felt compelled to post code here.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- | | | | re: unsigned long long Dan.Pop@cern.ch (Dan Pop) wrote in message news:<botdrb$ndv$8@sunnews.cern.ch>...[color=blue]
> In <bosba5$s39$3@sparta.btinternet.com> Richard Heathfield <dontmail@address.co.uk.invalid> writes:[color=green]
> > <snip>
> >Apart from Eric's comments, you may find it a good idea to cast the
> >expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
> >variadic function such as printf.[/color]
>
> Or, more generally, to the actual type expected by the respective
> conversion description.
>
> Unless you're using a conforming C99 implementation, there is no
> conversion description that is guarantee to properly handle a size_t
> value. Even worse, in the case of sizeof(type) * CHAR_BIT, the type
> of the expression can be either size_t or int.[/color]
....or unsigned int.
--
Peter | | | | re: unsigned long long
In <63f490f7.0311121916.10f303b5@posting.google.com > airia@acay.com.au (Peter Nilsson) writes:
[color=blue]
>Dan.Pop@cern.ch (Dan Pop) wrote in message news:<botdrb$ndv$8@sunnews.cern.ch>...[color=green]
>> In <bosba5$s39$3@sparta.btinternet.com> Richard Heathfield <dontmail@address.co.uk.invalid> writes:[color=darkred]
>> > <snip>
>> >Apart from Eric's comments, you may find it a good idea to cast the
>> >expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
>> >variadic function such as printf.[/color]
>>
>> Or, more generally, to the actual type expected by the respective
>> conversion description.
>>
>> Unless you're using a conforming C99 implementation, there is no
>> conversion description that is guarantee to properly handle a size_t
>> value. Even worse, in the case of sizeof(type) * CHAR_BIT, the type
>> of the expression can be either size_t or int.[/color]
>
>...or unsigned int.[/color]
ONLY if size_t is an alias of unsigned int (or a shorter unsigned type
with identical properties).
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de | | | | re: unsigned long long
In <3FB2E1EB.4496@earthlink.net> Joe Wright <joewwright@earthlink.net> writes:
[color=blue]
>Dan Pop wrote:[color=green]
>>
>> In <3FB16B89.37DD@earthlink.net> Joe Wright <joewwright@earthlink.net> writes:
>>[color=darkred]
>> >Try this.
>> >
>> >/*
>> > Sizes of various things in bits..
>> >*/
>> >#include <stdio.h>
>> >#include <limits.h>
>> >
>> >int main(void) {
>> > unsigned int a, b, c;
>> > unsigned long long x, y, z;
>> >
>> > c = -1;
>> > b = 1 << (sizeof(int)*CHAR_BIT-1);
>> > a = ~b;
>> >
>> > z = -1;
>> > y = 1LL << (sizeof(long long)*CHAR_BIT-1);
>> > x = ~y;
>> >
>> > printf("Size of void = %2lu bits\n", sizeof(void) *
>> >CHAR_BIT);
>> > printf("Size of char = %2lu bits\n", sizeof(char) *
>> >CHAR_BIT);
>> > printf("Size of short = %2lu bits\n", sizeof(short) *
>> >CHAR_BIT);
>> > printf("Size of int = %2lu bits\n", sizeof(int) *
>> >CHAR_BIT);
>> > printf("Size of long = %2lu bits\n", sizeof(long) *
>> >CHAR_BIT);
>> > printf("Size of long long = %2lu bits\n", sizeof(long long) *
>> >CHAR_BIT);
>> > printf("Size of int * = %2lu bits\n", sizeof(int *) *
>> >CHAR_BIT);
>> > printf("Size of char * = %2lu bits\n", sizeof(char *) *
>> >CHAR_BIT);
>> > printf("Size of void * = %2lu bits\n", sizeof(void *) *
>> >CHAR_BIT);
>> > printf("Size of float = %2lu bits\n", sizeof(float) *
>> >CHAR_BIT);
>> > printf("Size of double = %2lu bits\n", sizeof(double) *
>> >CHAR_BIT);
>> > printf("Size of long double = %2lu bits\n", sizeof(long double) *
>> >CHAR_BIT);
>> > printf("Max int = %11d\n", a);
>> > printf("Min int = %11d\n", b);
>> > printf("Max unsigned int = %11u\n", c);
>> > printf("Max long long = %20lld\n", x);
>> > printf("Min long long = %20lld\n", y);
>> > printf("Max unsigned long long = %20llu\n", z);
>> > return 0;
>> >}[/color]
>>
>> Try it yourself, with the compiler in conforming mode, this time!
>>[/color]
>Come on Dan, lighten up. As you have noted elsethread, we are not likely
>to have C99 conformance. Vanilla gcc compiles this fine.[/color]
Vanilla gcc doesn't compile C, and this is NOT a gratuitously pedantic
remark.
[color=blue]
>With -ansi
>-pedantic it complains about 'long long' of course. I've already
>forgotten why I felt compelled to post code here.[/color]
Even with -std=c99 -pedantic your code fails to compile cleanly, because
of sizeof(void) which is nonsense in C: void is an incomplete type.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de | | | | re: unsigned long long Dan.Pop@cern.ch (Dan Pop) wrote in message news:<bp048m$kuf$17@sunnews.cern.ch>...[color=blue]
> In <63f490f7.0311121916.10f303b5@posting.google.com > airia@acay.com.au (Peter Nilsson) writes:[color=green]
> >Dan.Pop@cern.ch (Dan Pop) wrote in message news:<botdrb$ndv$8@sunnews.cern.ch>...[color=darkred]
> >> In <bosba5$s39$3@sparta.btinternet.com> Richard Heathfield <dontmail@address.co.uk.invalid> writes:
> >> > <snip>
> >> >Apart from Eric's comments, you may find it a good idea to cast the
> >> >expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
> >> >variadic function such as printf.
> >>
> >> Or, more generally, to the actual type expected by the respective
> >> conversion description.
> >>
> >> Unless you're using a conforming C99 implementation, there is no
> >> conversion description that is guarantee to properly handle a size_t
> >> value. Even worse, in the case of sizeof(type) * CHAR_BIT, the type
> >> of the expression can be either size_t or int.[/color]
> >
> >...or unsigned int.[/color]
>
> ONLY if size_t is an alias of unsigned int (or a shorter unsigned type
> with identical properties).[/color]
What properties would need to be identical?
--
Peter | | | | re: unsigned long long
Dan Pop wrote:[color=blue]
>
> In <3FB2E1EB.4496@earthlink.net> Joe Wright <joewwright@earthlink.net> writes:
>[color=green]
> >Dan Pop wrote:[color=darkred]
> >>
> >> In <3FB16B89.37DD@earthlink.net> Joe Wright <joewwright@earthlink.net> writes:
> >>
> >> >Try this.
> >> >[/color][/color][/color]
[ code snipped ][color=blue][color=green][color=darkred]
> >>
> >> Try it yourself, with the compiler in conforming mode, this time!
> >>[/color]
> >Come on Dan, lighten up. As you have noted elsethread, we are not likely
> >to have C99 conformance. Vanilla gcc compiles this fine.[/color]
>
> Vanilla gcc doesn't compile C, and this is NOT a gratuitously pedantic
> remark.
>[color=green]
> >With -ansi
> >-pedantic it complains about 'long long' of course. I've already
> >forgotten why I felt compelled to post code here.[/color]
>
> Even with -std=c99 -pedantic your code fails to compile cleanly, because
> of sizeof(void) which is nonsense in C: void is an incomplete type.
>[/color]
You are completely right. I shouldn't ask you to lighten up on me. I
made at least four 'mistakes' in that code and you came down hard on two
of them. Thank you. I need to be more careful in what I write and what I
post.
I promise to be more careful in the future. Please keep trying to catch
me out.
Thanks.
--
Joe Wright http://www.jw-wright.com
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- | | | | re: unsigned long long
In <63f490f7.0311131340.71df64e8@posting.google.com > airia@acay.com.au (Peter Nilsson) writes:
[color=blue]
>Dan.Pop@cern.ch (Dan Pop) wrote in message news:<bp048m$kuf$17@sunnews.cern.ch>...[color=green]
>> In <63f490f7.0311121916.10f303b5@posting.google.com > airia@acay.com.au (Peter Nilsson) writes:[color=darkred]
>> >Dan.Pop@cern.ch (Dan Pop) wrote in message news:<botdrb$ndv$8@sunnews.cern.ch>...
>> >> In <bosba5$s39$3@sparta.btinternet.com> Richard Heathfield <dontmail@address.co.uk.invalid> writes:
>> >> > <snip>
>> >> >Apart from Eric's comments, you may find it a good idea to cast the
>> >> >expression sizeof(char) * CHAR_BIT to unsigned long before passing it to a
>> >> >variadic function such as printf.
>> >>
>> >> Or, more generally, to the actual type expected by the respective
>> >> conversion description.
>> >>
>> >> Unless you're using a conforming C99 implementation, there is no
>> >> conversion description that is guarantee to properly handle a size_t
>> >> value. Even worse, in the case of sizeof(type) * CHAR_BIT, the type
>> >> of the expression can be either size_t or int.
>> >
>> >...or unsigned int.[/color]
>>
>> ONLY if size_t is an alias of unsigned int (or a shorter unsigned type
>> with identical properties).[/color]
>
>What properties would need to be identical?[/color]
The range.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|