8

Why this code is not working?

#include <stdio.h>
main()
{
    UINT64_t ram = 90;
    printf("%d""\n", ram);
}

I got the Following errors:

In function \u2018main\u2019
error: \u2018UINT64_t\u2019 undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: expected \u2018;\u2019 before \u2018ram\u2019
9
  • 3
    #include <stdint.h> and uint64_t
    – Gopi
    Commented May 7, 2015 at 5:49
  • i got again same errors.
    – Ramakant
    Commented May 7, 2015 at 5:51
  • Did you change uint64_t?
    – Gopi
    Commented May 7, 2015 at 5:54
  • 1
    uint64_t, note the case. And the proper printf specifier for uint64_t is from <inttypes.h>, and uses literal-concatenation to form the proper spec, like this: printf("%" PRIu64 "\n", val);
    – WhozCraig
    Commented May 7, 2015 at 5:54
  • 2
    UINT64_t isn't a standard type or alias. Unless you typedef it yourself, you're going to get it from somewhere else. Ask the guy that gave you the code. The standard supplied version is uint64_t.
    – WhozCraig
    Commented May 7, 2015 at 5:58

3 Answers 3

14

uint64_t is defined in Standard Integer Type header file. ie, stdint.h. So first include stdint.h in your program.

Then you can use format specifier "%"PRIu64 to print your value: i.e.

printf("%" PRIu64 "\n", ram);

You can refer this question also How to print a int64_t type in C

1
  • 7
    Although uint64_t is defined in <stdint.h>, the macros such as PRIu64 are defined in <inttypes.h> instead. Unusually, <inttypes.h> effectively include <stdint.h>; no other standard C header includes another. Commented May 7, 2015 at 5:57
4

Full working example: http://ideone.com/ttjEOB

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

int main()
{
    uint64_t ram = 90;
    printf("%" PRIu64 "\n", ram);
}

You forgot some headers, wrote incorrectly uint64_t and can't use %d with uint64_t

2

Add:

#include <inttypes.h>

And use PRIu64 (outside of quotation marks like so):

printf("%"PRIu64"\n", ram);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.