[PATCH 1/2] Add generic LE/BE load/store uint type convertors and use them in msgb

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/baseband-devel@lists.osmocom.org/.

Sylvain Munaut 246tnt at gmail.com
Fri Mar 14 07:58:08 UTC 2014


Hi,

> +/* Load unaligned n-byte integer (little-endian encoding) into uintXX_t */
> +static inline uintXX_t osmo_loadXXle_ext(const uint8_t *p, uint8_t n)

Is "uint8_t *"   the right type here ? I would think "void *" to be better.

When loading from a msgb, sure we get uint8_t *  (well unsigned char *
actually, which just happen to match uint8_t  on our architecture).

But if you try to load a value from a struct pointer that might not be
aligned, you'll get possibly a int16_t or something and you'll need an
explicit cast. While casting to void * is implicit in C.

like :

struct test {
 int8_t foo;
 int16_t bar
};

struct test *tp = (struct test *) msgb->data;  /* Note that I'm not
especially happy with the explicit cast here either ... data should be
void* imho */

osmo_load16be(&tp->bar);

vs

osmo_load16be((uint8_t*)&tp->bar);


Cheers,

    Sylvain




More information about the baseband-devel mailing list