473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

long long data type

Recently I have had the need to run loops of at least 10^10 steps.
Since 32 bit integers apparently can only store values up to about
2*10^9, I have tried to use the "long long" data type. However, it has
not worked and I am unsure why. For example, I try the following code:

testlong.c:

#include <stdio.h>
#include <stdlib.h>

int main() {
long long a;
a = 10000000000LL; //10^10
printf("a = %i\n", a);
return EXIT_SUCCESS;
}

and compile it by:

gcc testlong.c -o testlong

then when I run the executable I obtain the following:

a = 1410065408

Does anyone know how to fix this problem? Perhaps gcc requires some
commandline argument to support long long ints?
Thanks for any suggestions.

Nov 14 '05 #1
5 10036
dijaster wrote:
Recently I have had the need to run loops of at least 10^10 steps.
[...]. For example, I try the following code:

testlong.c:

#include <stdio.h>
#include <stdlib.h>

int main() {
long long a;
a = 10000000000LL; //10^10
printf("a = %i\n", a);
As the format string specifies, printf expects it's second argument to
be an int.
return EXIT_SUCCESS;
}

and compile it by:

gcc testlong.c -o testlong

then when I run the executable I obtain the following:

a = 1410065408


You need to specify the long long length modifier (ll) to printf:
printf("%lli\n", a);

--
Robert Bauck Hamar
Nov 14 '05 #2
Thanks Robert. That seems to have solved the problem.

Nov 14 '05 #3
"dijaster" <di******@yahoo.com> writes:
Thanks Robert. That seems to have solved the problem.


Note that there may be systems on which the compiler supports
"long long", but the runtime library's implementation of printf()
doesn't (or supports it in a non-standard way).

The "long long" type was added to the language in the 1999 version of
the standard (C99), which is not yet widely implemented. Many pre-C99
compilers support it as an extension, but as I recall consensus on the
name of the type was reached before it was reached on the format
strings for printf.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #4
dijaster wrote:

Recently I have had the need to run loops of at least 10^10 steps.
Since 32 bit integers apparently can only store values up to about
2*10^9, I have tried to use the "long long" data type. However, it has
not worked and I am unsure why. For example, I try the following code:

testlong.c:

#include <stdio.h>
#include <stdlib.h>

int main() {
long long a;
a = 10000000000LL; //10^10
printf("a = %i\n", a);


Thats the wrong conversion character. Try:

printf("a = %llu\n", a);

Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo no****@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
Linux, the UNIX defragmentation tool.
Nov 14 '05 #5
On Mon, 20 Dec 2004 08:25:24 +1100, Erik de Castro Lopo wrote:
dijaster wrote:

Recently I have had the need to run loops of at least 10^10 steps.
Since 32 bit integers apparently can only store values up to about
2*10^9, I have tried to use the "long long" data type. However, it has
not worked and I am unsure why. For example, I try the following code:

testlong.c:

#include <stdio.h>
#include <stdlib.h>

int main() {
long long a;
a = 10000000000LL; //10^10
printf("a = %i\n", a);


Thats the wrong conversion character. Try:

printf("a = %llu\n", a);


%llu is for unsigned long long, for long long use %lld.

You CAN also use %lli. However %d forms are usually preferred over %i
because %d was the original, %i was only a later addition; it is possible
that some old compilers may not support %i, and %d is what C programmers
tend to be used to. d can be easier to read than i in some character
sets. Also remember that %d and %i do different things in scanf()
conversions, and %d is the closer match to the printf() behaviour.

Lawrence
Nov 14 '05 #6

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

Similar topics

7
by: Galina | last post by:
Hello I am going to copy a data from MS Access table into Oracle table. One of fields is memo type and data in this field range from 1 character to 551 long string. Do I need to create a field...
17
by: Adam Ierymenko | last post by:
I have a question that might have been asked before, but I have not been able to find anything via groups.google.com or any web search that is definative. I am writing an evolutionary AI...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
6
by: Stephen Cook | last post by:
Having worked through the problems around enabling the document function using an XmlUrlResolver I started work on building a useful class to hide the intricacies. Trying to generalise the process...
45
by: Trevor Best | last post by:
I did a test once using a looping variable, first dimmed as Integer, then as Long. I found the Integer was quicker at looping. I knew this to be true back in the 16 bit days where the CPU's (80286)...
29
by: Richard A. Huebner | last post by:
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...
7
by: bryan | last post by:
I think I'm missing something fundamental here. I'm trying to set an unsigned long value via a u_long pointer, however it coredumps everytime I get to that instruction. Here is a sample program...
3
by: RoSsIaCrIiLoIA | last post by:
I have rewrote the malloc() function of K&R2 chapter 8.7 typedef long Align; ^^^^ Here, should I write 'long', 'double' or 'long double'? I know that in my pc+compiler sizeof(long)=4,...
15
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this...
15
by: David Geering | last post by:
Is there any standard as to what a long and int mean or is it compiler dependent? Or furthermore architecture dependent? I know a short short long int isn't actually a recognised type, but if you...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.