Same output for htonl() and ntohl() on an integer

后端 未结 4 1068
甜味超标
甜味超标 2020-12-03 11:31

I ran the following program on little-endian [LE] machine [Linux, Intel processor]. I am unable to explain the 3 outputs in below code snippet. Since machine is LE, the valu

4条回答
  •  借酒劲吻你
    2020-12-03 11:40

    Because you're passing a by value and therefore it isn't changed by either of those functions.

    You're printing what htonl() and ntohl() are returning.

    Edit to add: I missed where you thought one would be a no-op. It's not. Both are going to do the exact same thing on a LE machine; reverse the byte ordering. ntohl() is expecting you to be passing it a network byte ordered int

提交回复
热议问题