I have problem with my c code, g++ compiler gives an error about long unsigned int when I try to printf same values. Here is my code and the errors that I get:
as3.c: warning: format %s expects type char *, but argument 2 has type onion
as3.c: warning: format %d expects type int, but argument 3 has type long unsigned int
as3.c: warning: format %d expects type int, but argument 3 has type long unsigned int
as3.c: warning: format %d expects type int, but argument 5 has type long unsigned int
as3.c: warning: format %d expects type int, but argument 2 has type long unsigned int
#define NUM1 5.557111111111111
#define NUM2 1937006915
#define NUM3 1668248096
#define NUM4 8555
#include <stdio.h>
typedef union {
char * a;
double num;
int * i;
}onion;
int main(int argc, char ** argv)
{
onion myoni;
char array[] = "TESTING";
int array2[] = { NUM2, NUM1, NUM3 };
myoni.a = array;
printf("char: %s, %d\n",myoni,sizeof(myoni.a));
myoni.num = NUM1;
printf("double: %10.15f, %d\n", myoni.num, sizeof(myoni.num));
myoni.i = array2;
printf("int: %d %d %d, %d\n", myoni.i[0], myoni.i[1],myoni.i[2], sizeof(myoni.i));
return 0;
}
Instead of:
use:
That is, pass a
char *forsconversion specifier and use the%zuconversion specification for the result of thesizeofoperator.