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 6345441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:49:21+00:00 2026-05-24T20:49:21+00:00

see i have one complex code but i m stuck up some where so

  • 0

see i have one complex code but i m stuck up some where so i m just giving you part of that..

i have one function

function(int a,uint64_t b,int c);

when i was calling function

  uint64_t b;
  int c;

  printf("enter b");
  scanf("%d",&b);  // i m giving 1

   printf("enter c");
   scanf("%d",&c);  // i m giving 2

  function(0xcd32ab00 ,b ,c);

in that function definition i m comparing value b with one another parameter like

 /*  magicNum is type uint64_t type & it has value 1 */
if(magicNum == b) 
{
 // do something
}

But that “do something” does not happen;
when i m printing magicNum & b both have value 1 so can not understand why this happen.

when i write

if((uint64_t)magicNum == (uint64_t)b) 
{
 // do something
}

this works perfectly.

i know i m doing one silly mistake but i m not getting…plz help me…
i m working on 32 bit linux system

  • 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-05-24T20:49:22+00:00Added an answer on May 24, 2026 at 8:49 pm

    There was something wrong with your original code that you didn’t show us. That’s because the following works fine:

    #include <stdio.h>
    
    static void fn (int a, uint64_t b, int c) {
        uint64_t magicNum = 1;
        if (magicNum == b)
            puts ("They match!");
        if ((uint64_t)magicNum == (uint64_t)b)
            puts ("They still match!");
    }
    
    int main (void) {
    
        fn (0xcd32ab00 ,1 ,2);
        return 0;
    }
    

    outputting:

    They match!
    They still match!
    

    Based on your update that you’re using scanf("%d") to get the values, this is a fairly well known problem to those of us that have been warped from decades of C usage 🙂

    When you provide %d as a format specifier, it expects a pointer to an int type, and it will write to that type. If the pointer you give it is to a type twice as wide (say 64 bits instead of 32), it will only write to half of it.

    You can see this here:

    int main (void) {
        uint64_t x = 0xffffffffffffffffULL;
        printf ("Enter your number: ");
        scanf ("%d", &x);     // signed int
        printf ("%llu\n", x); // unsigned long long
        return 0;
    }
    

    which outputs -4294967295 when you enter 1 (because it hasn’t touched the other half of the variable, which is still full of 1-bits).

    If you change the scanf format string to use %llu, it works fine.

    Keep in mind that this is only because my unsigned long long values are 64 bits wide, just like my unit64_t ones. For portability, you should be using the format specifier macros located in inttypes.h. For uint64_t, the correct one would be SCNu64. The macro names are formed by using:

    • PRI for printf format strings or SCN for scanf format strings.
    • d, i, o, u, x or X to specify signed decimal (d and i), unsigned octal, unsigned decimal, unsigned lower-case hex and unsigned upper-case hex.
    • optional LEAST, FAST, MAX or PTR for different variable types.
    • N which is the bit size.

    SCNu64 expands to "llu" on my implementation but that’s not necessarily the case everywhere. On a system that had 64 bit int and 256-bit long long, it would most likely be "u" (since it equates to an unsigned int).

    Sample code showing how to use these format strings is shown below:

    #include <stdio.h>
    #include <inttypes.h>
    
    int main (void) {
        uint64_t x = 0xffffffffffffffffULL;
        printf ("Enter your number: ");
        scanf ("%" SCNu64, &x);
        printf ("%" PRIu64 "\n", x);
        return 0;
    }
    

    As to why your printf may print out the reduced value, see this code:

    #include <stdio.h>
    #include <inttypes.h>
    
    int main (void) {
        uint64_t x = 0xffffffffffffffffULL;
        printf ("Enter your number: ");
        scanf ("%u", &x);
        printf ("uint64_t = %" PRIu64 "\n", x);
        printf ("uint64_t = %" PRIu64 " (when and'ed)\n", x & 0xffffffffU);
        printf ("uint     = %u\n", x);
        return 0;
    }
    

    which outputs:

    Enter your number: 5
    uint64_t = 18446744069414584325
    uint64_t = 5 (when and'ed)
    uint     = 5
    

    I suspect you’re printing it with the lower-size format string as well. When you do that, it’s actually an alignment problem. Because your processor is little-endian, it works by accident (the first 32 bits of a 64 bit value are the least significant bits, the 5 in the example above).

    But it will stuff up any arguments after that point in your printf because you’ve pushed 64 bits onto the stack and printf only consumes 32, hence the misalignment.

    See here and here for earlier answers explaining how this works (or, more correctly, doesn’t work).

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

Sidebar

Related Questions

Hello Guys! See I have been creating a code powered with ajax but it
Have a (rather complex) app that works fine on iOS 4 but fails on
I've been drying some code, one of this refactors is as following: I have
I have one text input and one button (see below). How can I use
I have this control (see picture). I like when check one option in this
Do bubble sorts have any real world use? Every time I see one mentioned,
I have see code like this Dim s as something = new something Dim
(resolved: see bottom) I have the following code snippet: Protected Sub SqlDataSource1_Inserted(ByVal sender As
I see an application have used Log.info = some info where are these logs
Is there a way to see users that have certain security role assigned? I'm

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.