Hé super intéressant, je ne connaissais pas ! Le 2 mars 2012 à 22:36, Marc Mongenet a écrit :
> Le 2 mars 2012 22:04, Philippe Strauss <[email protected]> a > écrit : >> les macros be64toh et compagnie acceptent un uint64_t en entrée, donc il >> y a le cast automatique floats <-> ints qui entre en action pas pour le >> meilleur dans ce cas. > > Tu veux dire msgp->payload.vol.volume est de type double ? > Dans ce cas, l'appel à be64toh serait bien trop tardif > et ça ne peux clairement pas marcher. > >> marrant, ocaml n'a pas de type champs de bits natif propre au langage, >> mais C non plus, C ne fait pas mieux dans ce cas. > > Oh si, C supporte les champs de bits (bit-field). > Ce n'est guère utilisé, mais tout à fait standard. > > #include <stdio.h> > > struct s { > unsigned bf0:8; > unsigned bf1:16; > unsigned bf2:4; > unsigned bf3:4; > }; > > union u { > struct s s; > unsigned char uc[4]; > }; > > int main(void) { > union u u; > > u.s.bf0 = 1; > u.s.bf1 = 2; > u.s.bf2 = 4; > u.s.bf3 = 8; > > printf("%x %x %x %x\n", u.uc[0], u.uc[1], u.uc[2], u.uc[3]); > return 0; > } par contre t'as tjr besoin d'une union avec un type standard dans le cas de fait du printf dessus ? > 22:34:33 marc@kameha /tmp > gcc -Wall c.c > 22:35:24 marc@kameha /tmp > ./a.out > 1 2 0 84 > 22:35:25 marc@kameha /tmp > > > Marc > _______________________________________________ > gull mailing list > [email protected] > http://forum.linux-gull.ch/mailman/listinfo/gull -- Philippe Strauss http://www.strauss-acoustics.ch/ _______________________________________________ gull mailing list [email protected] http://forum.linux-gull.ch/mailman/listinfo/gull
