problem about endianness-Collection of common programming errors


  • MOHAMED
    c build endianness htonl
    I m playing with open source which contains the following codeuint32_t addr = htonl(* (uint32_t *)RTA_DATA(rth)); if (htonl(13) == 13) {// running on big endian system } else {// running on little endian systemaddr = __builtin_bswap32(addr); }It looks like it check if the system is a big endian or little endian with if (htonl(13) == 13). is it correct? and could you please explain why the check this in t

  • alartur
    c type-conversion endianness
    I am looking for the fastest way to read numerical values stored in binary files.I have done some functions that seem to work, but I’d like to get a feedback on whether or not my implementation is good.Here is how I get a signed integer from a 4-bytes little endian block:signed long int from4li(char const * const buffer) {signed long int value = 0;value += (unsigned char) buffer[3];value

Originally posted 2013-11-09 19:45:12.