473,396 Members | 1,861 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,396 software developers and data experts.

How to output long long or int64?

I just want to output a long long or int64 variable use printf
function.But if I use printf("%ld",x); I can't output an x more than
long.
I can only output it like this:
long long a,b,c;
a=c/100000000;
printf("%ld",a);
b=c%100000000;
printf("%08ld\n",b);
How can I output it in an regular way?

Nov 15 '05 #1
26 104070
On 10 Nov 2005 23:12:17 -0800, "Be*****@gmail.com" <Be*****@gmail.com>
wrote:
I just want to output a long long or int64 variable use printf
function.But if I use printf("%ld",x); I can't output an x more than
long.
I can only output it like this:
long long a,b,c;
a=c/100000000;
printf("%ld",a);
b=c%100000000;
printf("%08ld\n",b);
How can I output it in an regular way?


long->printf("%ld"...
long long->printf("%lld"...

Intuitive.

Best regards,

-- Zara
Nov 15 '05 #2
On 2005-11-11, Be*****@gmail.com <Be*****@gmail.com> wrote:
I just want to output a long long or int64 variable use printf
function.But if I use printf("%ld",x); I can't output an x more than
long.
I can only output it like this:
long long a,b,c;
a=c/100000000;
printf("%ld",a);
b=c%100000000;
printf("%08ld\n",b);
How can I output it in an regular way?

"int64" is non-standard, and probably takes a non-standard format
specifier.

%lld for long long.
Nov 15 '05 #3
Zara:
I wrote:
#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
pfrintf("%lld",a);
}
But it outputs 705032699, why?

Nov 15 '05 #4
To Jordan Abel:
It's my mistake.I may wrote "__int64", not "int64"

I just get a way to output:
printf("%I64d",c);
It works well.

The reason "%lld" can't work is ä»–that my Dev-C++ didn't support
it.(Somebody says)

Nov 15 '05 #5
Zara:
I use Dev-C++ 4.9.9.2, Gcc 3.4.2

#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
printf("%lld",a);
}

It outputs 705032699, why?

Nov 15 '05 #6
Be*****@gmail.com wrote:
Zara:
I wrote:
#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
pfrintf("%lld",a);
}
But it outputs 705032699, why?


Probably long long is 32 bits wide in your system. Or you declared a as
being long instead of long long.

(99999999999 * 5) % (2^32) = 705032699

HTH

Nov 15 '05 #7
"Be*****@gmail.com" <Be*****@gmail.com> wrote:
I just want to output a long long or int64 variable use printf
function.But if I use printf("%ld",x); I can't output an x more than
long.


If you have C99, "%lld" will output a long long, and "%"PRId64 will
print an int64_t. Other macros in <inttypes.h> will provide similar
specifiers for other sized integers, least and fast types, and so on.

If you are using long long as an extension in a pre-C99 compiler, I'm
afraid this newsgroup can't help you; you'll have to read your manual.

Richard
Nov 15 '05 #8
"Antonio Contreras" <an*****@gmail.com> writes:
Be*****@gmail.com wrote:
Zara:
I wrote:
#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
pfrintf("%lld",a);
}
But it outputs 705032699, why?


Probably long long is 32 bits wide in your system. Or you declared a as
being long instead of long long.

(99999999999 * 5) % (2^32) = 705032699


Not likely. In C99, long long is required to be at least 64 bits.
Some C90 implementations support long long as an extension, but
there's not much point in making it 32 bits, and I've never heard of
an implementation that did so.

Most likely the runtime library's implementation of printf() doesn't
support "%lld", even if the compiler supports long long.

--
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 15 '05 #9
On 11 Nov 2005 00:05:23 -0800, "Be*****@gmail.com" <Be*****@gmail.com>
wrote:
Zara:
I use Dev-C++ 4.9.9.2, Gcc 3.4.2

#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
printf("%lld",a);
}

It outputs 705032699, why?


Just tried it. In GCC 3.4.2 the long long type hast 8 bytes, as
required by the standard, but it seems printf is not updated or is
broken when working with long long.

I don´t know if it works in later versions.

Sorry,

-- Zara
Nov 15 '05 #10
Betaver wrote:
To Jordan Abel:
It's my mistake.I may wrote "__int64", not "int64"

I just get a way to output:
printf("%I64d",c);
It works well.

The reason "%lld" can't work is ä»–that my Dev-C++ didn't support
it.(Somebody says)


The problem is that C99 is a non-adopted standard, and int64_t is
really something that comes from C99, not C90. This lack of a standard
means that older compilers supported 64bits in various different ways.
(Maybe when the next C++ standard comes out, stdint.h and inttypes.h
will becomes widely deployed, however its not guaranteed, and it does
nothing for current C compilers.)

A stop gap solution you can use that will work with your compiler today
is the following:

http://www.pobox.com/~qed/pstdint.h

Then you can do something like:

#include "pstdint.h"
...
int64_t v = INT64_C (9999999999999);
printf ("%" PRINTF_INT64_MODIFIER "d\n", v);

The point being that some compilers use "%lld", and others use "%I64d",
and pstdint.h tries to give you the right one.

--
Paul Hsieh
http://www.pobox.com/~qed/
http://bstring.sf.net/

Nov 15 '05 #11
Zara wrote:
On 11 Nov 2005 00:05:23 -0800, "Be*****@gmail.com" <Be*****@gmail.com>
wrote:
Zara:
I use Dev-C++ 4.9.9.2, Gcc 3.4.2

#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
printf("%lld",a);
}

It outputs 705032699, why?


Just tried it. In GCC 3.4.2 the long long type hast 8 bytes, as
required by the standard, but it seems printf is not updated or is
broken when working with long long.

I don´t know if it works in later versions.

Sorry,


Which options did you use. I compiled the above program with gcc 3.3.6
and it worked perfectly well. The command line arguments I provided
were:

gcc -W -Wall -std=c99 -pedantic

Nov 15 '05 #12
Thanks for all the excellent answers.
My complier is gcc 3.4.2 and can't use another one, so I decide output
like this:
printf("%I64d",c);
Is it all right?

Nov 15 '05 #13
Zara <yo****@terra.es> writes:
On 11 Nov 2005 00:05:23 -0800, "Be*****@gmail.com" <Be*****@gmail.com>
wrote:
Zara:
I use Dev-C++ 4.9.9.2, Gcc 3.4.2

#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
printf("%lld",a);
}

It outputs 705032699, why?


Just tried it. In GCC 3.4.2 the long long type hast 8 bytes, as
required by the standard, but it seems printf is not updated or is
broken when working with long long.

I don´t know if it works in later versions.


<SEMI-OT>
printf is part of the runtime library; it's not part of gcc.
</SEMI-OT>

--
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 15 '05 #14
On 11 Nov 2005 02:07:36 -0800, "Antonio Contreras" <an*****@gmail.com>
wrote:
Zara wrote:
On 11 Nov 2005 00:05:23 -0800, "Be*****@gmail.com" <Be*****@gmail.com>
wrote:
>Zara:
>I use Dev-C++ 4.9.9.2, Gcc 3.4.2
>
>#include <stdio.h>
>long long a;
>int main()
>{
> a=999999999;
> a*=5;
> printf("%lld",a);
>}
>
>It outputs 705032699, why?


Just tried it. In GCC 3.4.2 the long long type hast 8 bytes, as
required by the standard, but it seems printf is not updated or is
broken when working with long long.

I don´t know if it works in later versions.

Sorry,


Which options did you use. I compiled the above program with gcc 3.3.6
and it worked perfectly well. The command line arguments I provided
were:

gcc -W -Wall -std=c99 -pedantic


The same parameters. But the porblem is not in the compiler, but in
the library. Do you use the GCC 3.3.6 provided one, or another one?
Maybe printf broke somewhere between 3.3.6 and 3.4.2

-- Zara
Nov 15 '05 #15
But if I'll always use this header file and its printf("%I64d") works
well, is it OK?

Nov 15 '05 #16
Options:
g++.exe "E:\Work\Test.cpp" -o "E:\Work\Test.exe" -g3
-I"D:\Program\DevCpp\include\c++\3.3.1\backward"
-I"D:\Program\DevCpp\include\c++\3.3.1\mingw32"
-I"D:\Program\DevCpp\include\c++\3.3.1"
-I"D:\Program\DevCpp\lib\gcc\mingw32\3.4.2\inclu de"
-I"D:\Program\DevCpp\include\c++\3.4.2\backward"
-I"D:\Program\DevCpp\include\c++\3.4.2\mingw32"
-I"D:\Program\DevCpp\include\c++\3.4.2" -I"D:\Program\DevCpp\include"
-L"D:\Program\DevCpp\lib" -g3

If I am in a tournament the options must be like this.

Nov 15 '05 #17
Also what does "-g3" means?

Nov 15 '05 #18
Zara wrote:

<snip>
The same parameters. But the porblem is not in the compiler, but in
the library. Do you use the GCC 3.3.6 provided one, or another one?
Maybe printf broke somewhere between 3.3.6 and 3.4.2


There is no such thing as the gcc provided library. gcc uses whatever
library the system has or it is told to use, and this varies depending
on the OS you are using.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #19
Betaver wrote:
Also what does "-g3" means?


1) Please provide context. There is no guarantee that people have seen
or will ever see the article you are plying to, so your article needs to
be understandable in complete isolation. Search this group for "Google
context" to find how to do this and to see how often we have told people
about this. Then complain at Google for providing such a stupidly broken
interface.

2) If you want information about a specific compiler ask where that
compiler is topical, such as gnu.gcc.help, although I would suggest
reading the manual first, since the information you seek is in there.

--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #20
"Betaver" <Be*****@gmail.com> wrote:
Thanks for all the excellent answers.
My complier is gcc 3.4.2 and can't use another one, so I decide output
like this:
printf("%I64d",c);
Is it all right?


Not in C, it isn't. Maybe in Ganuck, but that's off-topic here; ask in
gnu.gcc.help (If I've remembered the name correctly; readily findable,
anyway).

Richard
Nov 15 '05 #21
Betaver wrote:
To Jordan Abel:
It's my mistake.I may wrote "__int64", not "int64"


Looks like you are trying quote messages using Google.

I think you will find the information below of value

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Nov 15 '05 #22
Betaver wrote:
Thanks for all the excellent answers.
My complier is gcc 3.4.2 and can't use another one, so I decide output
like this:
printf("%I64d",c);
Is it all right?

Have you tried..

#include <stdio.h>
long long a;
int main(void)
{
a = 999999999;
a *= 5;
printf("%lld\n", a);
return 0;
}

...a real C program?

With GCC 3.1 (DJGPP) this prints..
4999999995

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 15 '05 #23
Joe Wright wrote: With GCC 3.1 (DJGPP) this prints..
4999999995

Maybe the problem is my header file. But "%lld" isn't supported here.
Certainly "%I64d" works well.

Nov 15 '05 #24
>Joe Wright wrote:
With GCC 3.1 (DJGPP) this prints..
4999999995


With Dev-C++ 4.9.9.2 Gcc 3.4.2

Nov 15 '05 #25
Betaver wrote:
Joe Wright wrote:
With GCC 3.1 (DJGPP) this prints..
4999999995

With Dev-C++ 4.9.9.2 Gcc 3.4.2

The printf you are calling is Microsoft printf in CRTDLL.DLL
Apparently you are using the mingw version of gcc without glibc.
Use I64 in that system since it works.
Nov 15 '05 #26
Keith Thompson wrote:
Zara <yo****@terra.es> writes:
On 11 Nov 2005 00:05:23 -0800, "Be*****@gmail.com" <Be*****@gmail.com>
wrote:

Zara:
I use Dev-C++ 4.9.9.2, Gcc 3.4.2

#include <stdio.h>
long long a;
int main()
{
a=999999999;
a*=5;
printf("%lld",a);
}

It outputs 705032699, why?


Just tried it. In GCC 3.4.2 the long long type hast 8 bytes, as
required by the standard, but it seems printf is not updated or is
broken when working with long long.

I don´t know if it works in later versions.

<SEMI-OT>
printf is part of the runtime library; it's not part of gcc.
</SEMI-OT>

Under windows they are using crtdll.dll by Microsoft.
Nov 15 '05 #27

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

Similar topics

88
by: Matt | last post by:
Hi folks. Can you help with some questions? I gather that some types supported by g++ are nonstandard but have been proposed as standards. Are the long long and unsigned long long types still...
5
by: Piotr B. | last post by:
Hello, I use MingGW g++ 3.2.3 on Windows 2000/AMD Athlon XP. I tried to output a "long double" variable using stdio printf(). I've tried various %formats (%llf, %Lf etc.), but none of them...
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 =...
7
by: dmpk2k | last post by:
Forgive me if this is obvious to you. I feel somewhat foolish. I've scribbled together something that demonstrates my problem. It takes the product of all integers n squared, where n is 1..10. ...
3
by: Chris N. Hinds | last post by:
I have a question regarding accessing long long ints in unions. I have constructed a union with a double, two ints in a structure, and a long long int. When the double is loaded with a...
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...
4
by: Ray Dillinger | last post by:
Hi. I'm using GCC on a SuSE Linux distribution, and the following program doesn't work the way I expect. I'm using the conversion specifier for long long integers that's in the man pages, but...
12
by: wenmang | last post by:
Hi, I am using following Oracle Proc-C compiler: Pro*C/C++: Release 8.1.7.0.0 - Production on Thu Jun 15 15:57:32 2006 (c) Copyright 2000 Oracle Corporation. All rights reserved. I like to...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.