3 ms·
Personally I'd use: unsigned int a = 0xFFFF, not unsigned int a = -1. This is a classic case of a readability issue. 0xFFFF is, in my mind, much clearer on you
by edanm 16y ago
Personally I'd use: unsigned int a = 0xFFFF, not unsigned int a = -1.
This is a classic case of a readability issue. 0xFFFF is, in my mind, much clearer on your intention than -1. The only problem is that you're assuming a specific int size, but really, if you're working with bits, chances are good that you're working on a platform where you know the architecture size (at least on embedded platforms).
- samfoo 16y agoThe problem is that you can't be sure how many bytes and int is on any given platform. So your way is more readable, but not portable.
- deleted 16y ago[deleted]
- samfoo 16y agoCrap. This is why you don't respond without fully reading a comment. Where is my delete option? :-)
- alnayyir 16y agoTitle said safest. use -1 and leave a very short comment.
- saurik 16y agoI actually work with bits a lot without knowing what the type is at all: enter templates, exit simplicity. My answer is to use C++ ~static_cast<Type_>(0) or C ~((Type_) 0).