erjiang / usbscale

Reads weight data from USB scales.
GNU General Public License v3.0
90 stars 22 forks source link

le16toh won't compile on macOS, but not necessary #25

Closed TheWaterbug closed 1 year ago

TheWaterbug commented 2 years ago

I tried compiling this on my Mac, and received the error:

usbscale.c:311:30: warning: implicit declaration of function 'le16toh' is invalid in C99 [-Wimplicit-function-declaration] double weight = (double) le16toh(dat[5] << 8 | dat[4]);

But le16toh is an unnecessary no-op for Intel or Apple Silicon Macs anyway, so replacing that line with just:

double weight = (double) (dat[5] << 8 | dat[4]);

allows it to compile and run.

jscott0 commented 1 year ago

I don't have access to a macOS machine to test, but I suspect this is because le16toh is a non-standard function. It is, however, slated for inclusion in POSIX Issue 8, so macOS needs to get its act together if it plans to be conformant.