ext-phil.2.carmody@xxxxxxxxx writes: [snip] >>+/* Function shamelessly borrowed from hid-core.c. */ >>+ >>+static s32 snto32(__u32 value, unsigned n) >>+{ >>+ switch (n) { >>+ case 8: return ((__s8)value); >>+ case 16: return ((__s16)value); >>+ case 32: return ((__s32)value); > > Beware - this relies on sane behaviour from the current and future compilers, as the C standard doesn't mandate what should happen when shortening out of range signed values. [n869.txt: 6.3.1.1.#3] That's good to know. There's probably some much more complicated, but portable, way to write the operation -- I suspect we'll continue to rely on the compiler to be sane. >>+ } >>+ return value & (1 << (n - 1)) ? value | (-1 << n) : value; > > That signed left shift, however, is good old fashioned undefined behaviour. [n869.txt 6.5.7.#4] Which version is that from? The copy of C99 I have says the resulting value is -1 * (2 ** n) if that value can be represented. (A 6 May 2005 committee draft of TC2 says the same thing.) Until n > 31, the behavior should be standard-defined. Michael -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html