By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,403 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,403 IT Pros & Developers. It's quick & easy.

unsigned long long

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
29 Replies


P: n/a
Richard A. Huebner <en*****@yahoo.com> scribbled the following:
Is the unsigned long long primitive data type supported in ANSI
standard C?
In C99, yes. In C90, no. Most current implementations of ANSI standard
C are still C90.
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?


unsigned long.

--
/-- Joona Palaste (pa*****@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
Nov 13 '05 #2

P: n/a

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@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 comes
with RedHat linux 9.

If not, what data type will yield the largest unsigned integer for me?


unsigned long.


Actually GCC has supported "unsigned long long" for quite some time. MSVC
supports "unsigned __int64" which is a 64-bit type..

Tom
Nov 13 '05 #3

P: n/a
Richard A. Huebner wrote:
If not, what data type will yield the largest unsigned integer
for me?


I don't know how to answer your question.

uint64_t might be useful still?

Nov 13 '05 #4

P: n/a
Tom St Denis <to********@iahu.ca> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@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 comes
> with RedHat linux 9.
> If not, what data type will yield the largest unsigned integer for me?


unsigned long.

Actually GCC has supported "unsigned long long" for quite some time. MSVC
supports "unsigned __int64" which is a 64-bit type..


Yes, but hardly in ANSI standard C, or what?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Immanuel Kant but Genghis Khan."
- The Official Graffitist's Handbook
Nov 13 '05 #5

P: n/a

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@oravannahka.helsinki.fi...
Tom St Denis <to********@iahu.ca> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@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 comes > with RedHat linux 9.

> If not, what data type will yield the largest unsigned integer for me?
unsigned long.
Actually GCC has supported "unsigned long long" for quite some time.

MSVC supports "unsigned __int64" which is a 64-bit type..


Yes, but hardly in ANSI standard C, or what?


ANSI is old. I for one welcome our new ISO overlords.

Tom
Nov 13 '05 #6

P: n/a
Tom St Denis <to********@iahu.ca> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@oravannahka.helsinki.fi...
Tom St Denis <to********@iahu.ca> scribbled the following:
> "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
> news:bo**********@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 comes >> > with RedHat linux 9.
>>
>> > If not, what data type will yield the largest unsigned integer for me? >>
>> unsigned long.
> Actually GCC has supported "unsigned long long" for quite some time. MSVC > supports "unsigned __int64" which is a 64-bit type..


Yes, but hardly in ANSI standard C, or what?

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.

--
/-- Joona Palaste (pa*****@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
Nov 13 '05 #7

P: n/a

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@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.


Be that as it may "unsigned long long" is part of ISOC AFAIK.

Tom
Nov 13 '05 #8

P: n/a
Tom St Denis <to********@iahu.ca> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@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.

Be that as it may "unsigned long long" is part of ISOC AFAIK.


ISO C99, Tom. Not ISO C90.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon
Nov 13 '05 #9

P: n/a

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@oravannahka.helsinki.fi...
Tom St Denis <to********@iahu.ca> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@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.

Be that as it may "unsigned long long" is part of ISOC AFAIK.


ISO C99, Tom. Not ISO C90.


Tom assumes we're dealing with the latest not the oldest.

Otherwise crack out some K&R !

Tom
Nov 13 '05 #10

P: n/a
"Tom St Denis" <to********@iahu.ca> wrote in message
news:P1*****************@news04.bloor.is.net.cable .rogers.com...
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@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.


Be that as it may "unsigned long long" is part of ISOC AFAIK.


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
Nov 13 '05 #11

P: n/a
Richard A. Huebner wrote:

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


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 ---
Nov 13 '05 #12

P: n/a
Joe Wright wrote:

Richard A. Huebner wrote:

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


Try this.
[code snipped; see up-thread]


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

--
Er*********@sun.com
Nov 13 '05 #13

P: n/a
Joe Wright wrote:

<snip>
printf("Size of char = %2lu bits\n", sizeof(char) *
CHAR_BIT);


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 : bi****@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
Nov 13 '05 #14

P: n/a
Eric Sosman wrote:

Joe Wright wrote:

Richard A. Huebner wrote:

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


Try this.
[code snipped; see up-thread]


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

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 ---
Nov 13 '05 #15

P: n/a
Richard Heathfield wrote:

Joe Wright wrote:

<snip>
printf("Size of char = %2lu bits\n", sizeof(char) *
CHAR_BIT);


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.

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 ---
Nov 13 '05 #16

P: n/a
In <bo**********@sparta.btinternet.com> Richard Heathfield <do******@address.co.uk.invalid> writes:
Joe Wright wrote:

<snip>
printf("Size of char = %2lu bits\n", sizeof(char) *
CHAR_BIT);


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.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #17

P: n/a
In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:
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;
}


Try it yourself, with the compiler in conforming mode, this time!

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #18

P: n/a
In <z4*****************@news04.bloor.is.net.cable.rog ers.com> "Tom St Denis" <to********@iahu.ca> writes:

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@oravannahka.helsinki.fi...
Tom St Denis <to********@iahu.ca> scribbled the following:
> "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
> news:bo**********@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.

> Be that as it may "unsigned long long" is part of ISOC AFAIK.


ISO C99, Tom. Not ISO C90.


Tom assumes we're dealing with the latest not the oldest.


An excellent illustration of the point I've made in another thread.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #19

P: n/a
In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:
Richard Heathfield wrote:

Joe Wright wrote:

<snip>
> printf("Size of char = %2lu bits\n", sizeof(char) *
> CHAR_BIT);


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.

Hmm.. size_t is unsigned long on my system. But I guess we're not
supposed to know that.


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: Da*****@ifh.de
Nov 13 '05 #20

P: n/a

"Dan Pop" <Da*****@cern.ch> wrote in message
news:bo**********@sunnews.cern.ch...
In <z4*****************@news04.bloor.is.net.cable.rog ers.com> "Tom St Denis" <to********@iahu.ca> writes:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bo**********@oravannahka.helsinki.fi...
Tom St Denis <to********@iahu.ca> scribbled the following:
> "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
> news:bo**********@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.

> Be that as it may "unsigned long long" is part of ISOC AFAIK.

ISO C99, Tom. Not ISO C90.


Tom assumes we're dealing with the latest not the oldest.


An excellent illustration of the point I've made in another thread.


Tom von Tom has ways of making you talk!

Tom
Nov 13 '05 #21

P: n/a

Get your Server or Homepage now

Choose which one you prefer.
Redhat, Debian, FreeBSD, Mandrake, Windows, SUSE
http://www.comserver.net
Nov 13 '05 #22

P: n/a
Jonathan2s6 <jo*********@aol.com> scribbled the following:
Get your Server or Homepage now Choose which one you prefer.
Redhat, Debian, FreeBSD, Mandrake, Windows, SUSE


Get lost.

--
/-- Joona Palaste (pa*****@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
Nov 13 '05 #23

P: n/a
Dan Pop wrote:

In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:
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;
}


Try it yourself, with the compiler in conforming mode, this time!

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 ---
Nov 13 '05 #24

P: n/a
Da*****@cern.ch (Dan Pop) wrote in message news:<bo**********@sunnews.cern.ch>...
In <bo**********@sparta.btinternet.com> Richard Heathfield <do******@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.

--
Peter
Nov 13 '05 #25

P: n/a
In <63**************************@posting.google.com > ai***@acay.com.au (Peter Nilsson) writes:
Da*****@cern.ch (Dan Pop) wrote in message news:<bo**********@sunnews.cern.ch>...
In <bo**********@sparta.btinternet.com> Richard Heathfield <do******@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.


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: Da*****@ifh.de
Nov 13 '05 #26

P: n/a
In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:
Dan Pop wrote:

In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:
>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;
>}
Try it yourself, with the compiler in conforming mode, this time!

Come on Dan, lighten up. As you have noted elsethread, we are not likely
to have C99 conformance. Vanilla gcc compiles this fine.


Vanilla gcc doesn't compile C, and this is NOT a gratuitously pedantic
remark.
With -ansi
-pedantic it complains about 'long long' of course. I've already
forgotten why I felt compelled to post code here.


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: Da*****@ifh.de
Nov 13 '05 #27

P: n/a
Da*****@cern.ch (Dan Pop) wrote in message news:<bp***********@sunnews.cern.ch>...
In <63**************************@posting.google.com > ai***@acay.com.au (Peter Nilsson) writes:
Da*****@cern.ch (Dan Pop) wrote in message news:<bo**********@sunnews.cern.ch>...
In <bo**********@sparta.btinternet.com> Richard Heathfield <do******@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.


ONLY if size_t is an alias of unsigned int (or a shorter unsigned type
with identical properties).


What properties would need to be identical?

--
Peter
Nov 13 '05 #28

P: n/a
Dan Pop wrote:

In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:
Dan Pop wrote:

In <3F***********@earthlink.net> Joe Wright <jo********@earthlink.net> writes:

>Try this.
> [ code snipped ]
Try it yourself, with the compiler in conforming mode, this time!

Come on Dan, lighten up. As you have noted elsethread, we are not likely
to have C99 conformance. Vanilla gcc compiles this fine.


Vanilla gcc doesn't compile C, and this is NOT a gratuitously pedantic
remark.
With -ansi
-pedantic it complains about 'long long' of course. I've already
forgotten why I felt compelled to post code here.


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.

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 ---
Nov 13 '05 #29

P: n/a
In <63**************************@posting.google.com > ai***@acay.com.au (Peter Nilsson) writes:
Da*****@cern.ch (Dan Pop) wrote in message news:<bp***********@sunnews.cern.ch>...
In <63**************************@posting.google.com > ai***@acay.com.au (Peter Nilsson) writes:
>Da*****@cern.ch (Dan Pop) wrote in message news:<bo**********@sunnews.cern.ch>...
>> In <bo**********@sparta.btinternet.com> Richard Heathfield <do******@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.


ONLY if size_t is an alias of unsigned int (or a shorter unsigned type
with identical properties).


What properties would need to be identical?


The range.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #30

This discussion thread is closed

Replies have been disabled for this discussion.