473,761 Members | 8,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
29 19619
"Tom St Denis" <to********@iah u.ca> wrote in message
news:P1******** *********@news0 4.bloor.is.net. cable.rogers.co m...
"Joona I Palaste" <pa*****@cc.hel sinki.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)*CH AR_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.pow ernet.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**********@s parta.btinterne t.com> Richard Heathfield <do******@addre ss.co.uk.invali d> 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********@ear thlink.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)*CH AR_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.bl oor.is.net.cabl e.rogers.com> "Tom St Denis" <to********@iah u.ca> writes:

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6908
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 = 916905990LL; \* then reatedly form the 64-bit t = a*x+c, after which the new carry c is the top 32, and the new x (output), is the bottom 32 bits of t:
1
3004
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
5454
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 addition overflows or underflows? Thanks, -Peter
36
5316
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 between 0 and 7 (=2^3-1). Could someone please help out? I can assume the largest returned value fits in an int. Also, I'm on a big-endian PPC (AIX), in case that matters. Ideally, I'd like to implement a prototype like: int...
9
3952
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
13184
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 long. I got 0 to -1 for both. The expected answers should be: unsigned int: 0 to 65535 unsigned long: 0 to 4294967295
9
6425
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
2650
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), sometimes int and long int are the same, and long long int is twice the width; or sometimes both long int and long long int are twice the width of int. This apparently all quite normal according to my c99 draft and c-faq.com. However it doesn't...
17
7561
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
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9923
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.