i'm just wondering how can i compare a union with other integer, my purpose is to code a sort of printf like and i'm managing the simple case like %d/%u/%i considering the size conversion : ll/l/hh/h/j/z, so basically i've the following union :
union all_integer
{
char c;
signed int nb;
short int snb;
long int lnb;
long long int llnb;
size_t posnb;
unsigned char uc;
unsigned int unb;
unsigned short int usnb;
unsigned long int ulnb;
unsigned long long int ullnb;
};
because i can't know before which type i'll need to receive, and after that when i've something like that in case i use %d :
union all_integer u_allint;
u_allint.nb = va_arg(ap, int);
i want to print my data wich's in my union u_allint so i give my union to a simple function for putmydata for exemple :
putdata(union all_integer u_allint)
{
if (u_allint < 0)
{
return (ft_numlen_neg(u_allint));
}
if (u_allint > 9)
return (1 + ft_numlen(u_allint / 10));
if (u_allint > 0 && u_allint < 10)
return (1);
if (u_allint == 0)
return (1);
return (0);
}
just suppose that this function is capable to print correctly my data and the fact is i can't do that because i compare an union with an int and even if i try to do an other union in my function and give newunion.nb = 0 for have an union int compare with an union int, i can't compile with this message : invalid operands to binary expression ('union my_union' and 'union my_union'). so i'm pretty sure that i misunderstand something about union, but i didn't find a similar problem in other topic, so am i misunderstand something or maybe taking the problem by the wrong way ? thank for your rep !