Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8408341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:36:21+00:00 2026-06-09T23:36:21+00:00

I have implemented below code : #include<stdio.h> #include<string.h> #include<ctype.h> #include<cstdlib> #include<sys/types.h> main() { int64_t

  • 0

I have implemented below code :

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<cstdlib>
#include<sys/types.h>
main()
{
    int64_t i64value1 = 0;
    int64_t i64value2 = 0;
    long long llvalue = 0;
    const char *s = "10811535359";
    i64value1 = atoll(s);
    llvalue = atoll(s);
    i64value2 = llvalue;
    printf("s : [%s]\n",s);
    printf("i64value1 : [%d]\n",i64value1);
    printf("llvalue : [%lld]\n",llvalue);
    printf("i64value2 : [%d]\n",i64value2);
}

Output of the above progrom is :

s : [10811535359]
i64value1 : [-2073366529]
llvalue : [10811535359]
i64value2 : [-2073366529]

The compiler used is :

 gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)

The OS is x86_64 GNU/Linux 2.6.18-194

Since long long is a signed 64-bit integer and is, for all intents and purposes, identical to int64_t type, logically int64_t and long long should be equivalent types. And some places mention to use int64_t instead of long long.
But when I look at stdint.h, it tells me why I see the above behavior:

# if __WORDSIZE == 64 
typedef long int  int64_t; 
# else 
__extension__ 
typedef long long int  int64_t; 
# endif 

In a 64-bit compile, int64_t is long int, not a long long int.

My Question is, Is there a workaround/solution to assign long long returned value to int64_t without losing the precision in 64 bit Machine?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:36:22+00:00Added an answer on June 9, 2026 at 11:36 pm

    The loss does not happen in the conversions but in the printing:

    printf("i64value1 : [%d]\n",i64value1);
    

    The int64_t argument is accessed as if it were an int. This is undefined behaviour, but usually the low 32 bits are sign extended.

    Proper compiler warnings (such as gcc -Wformat) should complain about this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented the multistage authentication illustrated below. brackets ([ and ]) symbolizes a
I have some classes as below, i have implemented the Equals(Object) method for almost
I have the interface defined as below and is implemented by a single class
I have implemented correctly bump's api, and added this code: - (void) configureBump {
I have an C++ application (heavily shortened down, shown below); #include <iostream> #include MyClass.h
I have a State class that is fully implemented as outlined below. I also
I have implemented the cancan with active_admin using below link. https://github.com/gregbell/active_admin/wiki/How-to-work-with-cancan Just in my
I have a class that implements InvocationHandler as below: public class MyProxyClass implements InvocationHandler
I have implemented pagination to my data, but the problem is I only have
I have implemented a table view with multiple threads. Currently when a user taps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.