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

前端 未结 6 605
一向
一向 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 18:00

    This conversion is safe if you are filling same value in all 4 bytes. If byte order matters then this conversion is not safe. Because when you use integer to fill 4 Bytes at a time it will fill 4 Bytes but order depends on the endianness.

提交回复
热议问题