Hacker News new | past | comments | ask | show | jobs | submit login

memset() is bytewise, the only reason it works with -1 is all the bits are set in every bit width. 0xff repeated still ends up being -1 at int size (0xffffffff). But the byte 0x2a repeated will be something more like 0x2a2a2a2a, which is not equivalent to 0x2a.



Right. So the translation was idiomatic but wrong.


I'd say the C++ was wrong/unclear. If you want all the ints in your array to be a certain number, use std::fill. If you want all their bits to be 1, use something like ~0 in the memset.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: