htonl() vs __builtin_bswap32()

前端 未结 3 1960
我寻月下人不归
我寻月下人不归 2021-02-10 04:16

__builtin_bswap32() is used to reverse bytes (it\'s used for littel/big endian issues (from gcc)).

htonl() is used to reverse bytes too (conver

3条回答
  •  梦毁少年i
    2021-02-10 04:52

    bswap_32 always reverse byte order, on any architecture.

    htonl/ntohl reverses byteorder on little endian machines only.

    For example, on PowerPC (big endian), ntohl/htonl just returns input value, no more, while bswap32 anyway will reverse byte order.

提交回复
热议问题