How to print guint64 value when using glib?

Problem

I am using the GLib 2.0 library and declaring a gunit64 variable. I want to print its value for the screen, but it does not work properly.

the code

As an example, consider the following code snippet. I declare a guint64 variable and try to print its value.

guint64 myValue = 24324823479324;
printf("My Value: %d\n", myValue);

Attention

I get this warning:

warning: format β€˜%d’ expects argument of type β€˜int’, but argument 2 has type β€˜guint64’ 

Output

A strange negative number appears on the screen:

My value: -1871285220

Additional comments

I tried to search the API documentation and I found the following under guint64:

An unsigned integer guaranteed to be 64 bits on all platforms. Values ​​of this type can range from 0 to G_MAXUINT64 (= 18,446,744,073,709,551,615).

, G_GINT64_MODIFIER / G_GUINT64_FORMAT.

, . , . - ?

+5
1

. :

printf("My value: %" G_GUINT64_FORMAT "\n", myValue);

, , . , % .

, %d, int, , , int, - .

+9

All Articles