Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print UINT64_t in gcc?

Tags:

c

function

unix

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
like image 825
Ramakant Avatar asked May 07 '15 05:05

Ramakant


3 Answers

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

like image 108
niyasc Avatar answered Oct 22 '22 22:10

niyasc


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

like image 4
xanatos Avatar answered Oct 22 '22 22:10

xanatos


Add:

#include <inttypes.h>

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

printf("%"PRIu64"\n", ram);
like image 2
ckolivas Avatar answered Oct 22 '22 22:10

ckolivas