Setting a buffer of char* with intermediate casting to int*

前端 未结 6 575
一向
一向 2021-01-11 17:23

I could not fully understand the consequences of what I read here: Casting an int pointer to a char ptr and vice versa

In short, would this work?

set         


        
6条回答
  •  感情败类
    2021-01-11 17:42

    In addition to the endian issue, which has already been mentioned here:

    CHAR_BIT - the number of bits per char - should also be considered.

    It is 8 on most platforms, where for (int i=0; i<4; i++) should work fine.

    A safer way of doing it would be for (int i=0; i.

    Alternatively, you can include and use for (int i=0; i<32/CHAR_BIT; i++).

提交回复
热议问题