unsigned long long

R

Richard A. Huebner

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
 
J

Joona I Palaste

Richard A. Huebner said:
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.
 
T

Tom St Denis

Joona I Palaste said:
unsigned long.

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

Tom
 
N

Nudge

Richard said:
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?
 
J

Joona I Palaste

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?
 
J

Joona I Palaste

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 ([email protected]) ------------- 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
 
T

Tom St Denis

Joona I Palaste said:
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
 
J

Joe Wright

Richard said:
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;
}
 
E

Eric Sosman

Joe said:
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
 
R

Richard Heathfield

Joe Wright wrote:

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.
 
J

Joe Wright

Eric said:
Joe said:
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?
 
J

Joe Wright

Richard said:
Joe Wright wrote:



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.
 
D

Dan Pop

In said:
Joe Wright wrote:



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
 
D

Dan Pop

In said:
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
 
D

Dan Pop

In said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top