472,958 Members | 1,994 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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

"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
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
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

"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
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

"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
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

"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
"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
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
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
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
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
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
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
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
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
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

"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

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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George Marsaglia | last post by:
The essence of a multiply-with-carry RNG is to have declarations in the RNG proc, such as unsigned long mwc( ){ static unsigned long x = 123456789, c = 362436; unsigned long long t, a =...
1
by: Sushil | last post by:
hi Gurus I'm a newbie learning C. I've a question, relevant code snippet is as follows : typedef unsigned long long ulonglong; struct foo { unsigned dummy : 2; unsigned n : 24;
12
by: Peter Ammon | last post by:
When I add an unsigned long long and an int, what type do each of the values get promoted to before the addition is performed? What is the type of the resulting expression? What occurs if the...
36
by: Digital Puer | last post by:
Hi, suppose I have an unsigned long long. I would like to extract the front 'n' bits of this value and convert them into an integer. For example, if I extract the first 3 bits, I would get an int...
9
by: luke | last post by:
Hi everybody, please, can someone explain me this behaviour. I have the following piece of code: long long ll; unsigned int i = 2; ll = -1 * i; printf("%lld\n", ll);
3
by: Nicholas Zhou | last post by:
Hi, I was writing a testing program to test the ranges of char, short, int and long variables on my computer, both signed and unsigned. Everything was fine except for unsigned int and unsigned...
9
by: vadivel.ks | last post by:
hi, My code having unsigned long long int64_t; like that.. compile error message is long followed by long is illegal, what is the reason for it?
21
by: Bart C | last post by:
I've always had a problem knowing exactly how wide my integer variables were in C, and the little program below has increased my confusion. Run on 3 compilers on the same cpu (32-bit pentium),...
17
by: Tarique | last post by:
This program was compiled on MS Visual C++ 08 /*Fibonacci Numbers*/ #include<stdio.h> #include<limits.h> void fibonacci(int n) { unsigned long long fib0 = 0; /*First Fibonacci Number*/
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.