printf a 64-bit number | Bytes (2024)

Home Posts Topics Members FAQ

Richard Cavell

GCC 3.3, XCode:
#include <iostream>
#include <stdint.h>

int main (int argc, char * const argv[])
{
uint64_t a=10123123123LL ;
printf("%d\n", a);
std::cout << a;
std::cout << "\n";
return 0;
}

The printf statement gives me 2 (which is the upper 32 bits of a). The
cout gives me the correct result. Is this expected behaviour? Surely
64 bit integers are de rigeur now.

I'm generally trying to use C and not C++ for portability and speed.

Jul 23 '05 #1

3 printf a 64-bit number | Bytes (1) 8367 printf a 64-bit number | Bytes (2)

void

Richard Cavell wrote:

GCC 3.3, XCode:
#include <iostream>
#include <stdint.h>

int main (int argc, char * const argv[])
{
uint64_t a=10123123123LL ;
printf("%d\n", a);

printf("%lld\n" , a);

Best
Darek

Jul 23 '05 #2

Rolf Magnus

Richard Cavell wrote:

GCC 3.3, XCode:
#include <iostream>
#include <stdint.h>

int main (int argc, char * const argv[])
{
uint64_t a=10123123123LL ;
printf("%d\n", a);
std::cout << a;
std::cout << "\n";
return 0;
}

The printf statement gives me 2 (which is the upper 32 bits of a). The
cout gives me the correct result. Is this expected behaviour?
Yes. You specified %d to printf, which means that you promised to pass an
int. But since you didn't actually pass an int, the result will be wrong.
Surely 64 bit integers are de rigeur now.

I'm generally trying to use C and not C++ for portability and speed.

What makes you believe printf is more portable and faster than cout? Do you
have any evidence that proves this?

Jul 23 '05 #3

msalters

Richard Cavell wrote:

GCC 3.3, XCode:
#include <iostream>
#include <stdint.h>

int main (int argc, char * const argv[])
{
uint64_t a=10123123123LL ;
printf("%d\n", a);
std::cout << a;
std::cout << "\n";
return 0;
}

The printf statement gives me 2 (which is the upper 32 bits of a).The cout gives me the correct result. Is this expected behaviour?Surely 64 bit integers are de rigeur now.

I'm generally trying to use C and not C++ for portability and speed.

Well, uint64_t isn't really portable. But I guess this shows:
with C it's easy to be wrong everywhere. You're probably very fast
in producing the wrong answer, but C++ is even faster:
in main() { } also produces the wrong output. It's also smaller.
The moral: being right is more important than petty concerns.

HTH,
Michiel Salters

Jul 23 '05 #4

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

Similar topics

14 7995

most accurate printf("%f")

by: Gernot Frisch |last post by:

Hi, I want to represent a double in char* as accurate as possible, but as short as possible: double char* 10000 1E5 1000.00123 1000.00123 ....

C / C++

16 19715

a printf implementation

by: Jordan Abel |last post by:

I have written this function and was wondering if anyone else could point out if there's anything wrong with it. The purpose is to substitute for printf when in a situation where low-level I/O has to be used for whatever reason, and memory allocation cannot be used - mainly it's become for me an exercise in interpreting printf-like format strings, and i thought i'd post it here to see if anyone can point out any bugs in it - i.e. anything...

C / C++

6 3561

Printf problem with big numbers....

by: pasukaru |last post by:

I need to work with big integers ( around 2.^64), and I know it is not possible to have integer that big. So I use "double" instead, and it is ok with calculations. But when I want to print them on screen or in a file, there is a problem... For example, if I write this : printf("result: %lf\n",1234567890987654321.012345678);

C / C++

16 2784

printf("%s", myclass) prints vtable instead of m_data

by: Gernot Frisch |last post by:

Hi, class MyString { char* m_data; public: MyString(const char* c) { m_data = new char; strcpy(m_data, c);

C / C++

34 16016

Usefulness of %hd in printf

by: Old Wolf |last post by:

Is there any possible situation for printf where %hd causes a different result to %d, and the corresponding argument was of type 'short int' ?

C / C++

18 422

printf

by: Shane |last post by:

Hi all, I am learning C, and I have a problem with printf. I have a pointer that points to binary data, and I want to print that data out. If I cast the pointer to (char *) then the data is printed out in the UniCode(?) equivalent of the data. If I try to cast to (int *) then I only get the address of the pointer (I think). What I really want is all the ones and zeros to be printed out. Any help appreciated TIA --

C / C++

2 3208

by: wombat |last post by:

Is there a way to prevent rounding when using printf for print a double/float? Example: double x=3.51; printf("%.0f\n", x); The output of this is 4, when I want it to be 3.

C / C++

7 19011

gcc printf conversion specification for struct timeval

by: PawelCarqowski |last post by:

Hallo group members, Do You know any conversion specification for this. I imagine: struct timeval time; printf("%T\n", time); regards, Pawel

C / C++

5 2771

Is this printf okay?

by: Jerry Newsome |last post by:

If sizeof(int) = sizeof(long), is this undefined behavior or is it okay? #include <stdio.h> int main(void) { int i = 5; long l = 7; printf("i = %ld\n", i); printf("l = %d\n", l); return 0;

C / C++

14 3984

printf() causes core dump

by: Sheldon |last post by:

Hi, Can anyone tell me why this script file.c and file.h causes a core dump when it is compiled and run? Any help is appreciated. Sheldon snip....

C / C++

9611

Changing the language in Windows 10

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

Windows Server

10408

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...

Online Marketing

1 10428

The easy way to turn off automatic updates for Windows 10/11

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

Windows Server

10145

Discussion: How does Zigbee compare with other wireless protocols in smart home applications?

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

General

9226

AI Job Threat for Devs

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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...

Career Advice

5570

Trying to create a lan-to-lan vpn between two differents networks

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

Networking - Hardware / Configuration

5710

Windows Forms - .Net 8.0

by: adsilva |last post by:

A Windows Forms form does not have the event Unload, like VB6. What one acts like?

Visual Basic .NET

1 4359

transfer the data from one system to another through ip address

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

C# / C Sharp

3 3030

Comprehensive Guide to Website Development in Toronto: Expert Insights from BSMN Consultancy

by: bsmnconsultancy |last post by:

In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

General

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

To disable or enable advertisem*nts and analytics tracking please visit the page.

printf a 64-bit number | Bytes (2024)

References

Top Articles
Latest Posts
Article information

Author: Rev. Porsche Oberbrunner

Last Updated:

Views: 6145

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Rev. Porsche Oberbrunner

Birthday: 1994-06-25

Address: Suite 153 582 Lubowitz Walks, Port Alfredoborough, IN 72879-2838

Phone: +128413562823324

Job: IT Strategist

Hobby: Video gaming, Basketball, Web surfing, Book restoration, Jogging, Shooting, Fishing

Introduction: My name is Rev. Porsche Oberbrunner, I am a zany, graceful, talented, witty, determined, shiny, enchanting person who loves writing and wants to share my knowledge and understanding with you.