On 07/28/2014 12:00 PM, Matthieu CASTET wrote: > Do you have suggestion how to read float/double in a portable way ? > Is RL32/RL64 is enough ?
It definitely isn't. Float and double are structured formats with fields spread across byte boundaries. You need to reverse the order of those fields, and thus pack them differently. The lascar-el-usb driver has a need for this: it supplies floats in little-endian, and the driver needs to read these into a local float: http://sigrok.org/gitweb/?p=libsigrok.git;a=blob;f=src/hardware/lascar-el-usb/api.c;h=04f844b3318b1d575a4eec0a8f23708e59a162a9;hb=HEAD#l268 As it happens I find myself needing the reverse now as well, for a file format that needs little-endian floats written to it. > PS : speaking of alignment problem, there is a candidate in wav > format_match [1]. buf is a char and may be not aligned on 16 bits. And > "*(uint16_t *)(buf + 20)" will do an unaligned access. > > [1] > static int format_match(const char *filename) > { > char buf[40]; > > if (get_wav_header(filename, buf) != SR_OK) > return FALSE; > > if (strncmp(buf, "RIFF", 4)) > return FALSE; > if (strncmp(buf + 8, "WAVE", 4)) > return FALSE; > if (strncmp(buf + 12, "fmt ", 4)) > return FALSE; > if (GUINT16_FROM_LE(*(uint16_t *)(buf + 20)) != 1) > /* Not PCM. */ > return FALSE; > if (strncmp(buf + 36, "data", 4)) > return FALSE; > > return TRUE; > } I don't get it, how would that not be aligned on 16 bits? It's allocated memory + 20 bytes. -- Bert Vermeulen [email protected] email/xmpp ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ sigrok-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sigrok-devel

