Why not simply let the read_int*() functions return all signed values instead?
Because signed values are rather rare in protocols and file formats.
This would:
- Increase the chance of the return value fitting into the native int type.'
Well, sometimes.
- Still allow easy reading of unsigned values (if one insists) by masking the output at the reader end by the appriopriate amount of bits (which is more efficient in Pike than creating a signed from an unsigned).
Not with bignums, actually. And that's the most common use with SSL, as an example. Also, it would mean that each and every time you read a byte or short or whatever you also have to have a matching &.
It would also break hstring reading rather badly, so you would still need the functions to read unsigned numbers internally.
Also, with native integers, as it turns out, it's fairly equal on x86_64 at least, where the integer operations are inlined.
Just add another function to read signed integers.
And as for byteorder, just add a switch to switch byteorder if the number of functions needs to be kept down for some reason.