4 ms·
Yes, to_string would have been better The C-style cast is shorter, but less safe, so you should not use it: http://stackoverflow.com/questions/1609163/what-is-
by daivd 14y ago
Yes, to_string would have been better
The C-style cast is shorter, but less safe, so you should not use it: http://stackoverflow.com/questions/1609163/what-is-the-difference-between-static-cast-and-c-style-casting http://stackoverflow.com/questions/1609163/what-is-the-diffe...
Yeah, I couldn't quite decide if I should include const refs. On the one hand, it is idiomatic, but on the other hand I didn't want to clutter the code with something that is just an optimization on paper.
- fafner 14y agoI know the C-style casts are bad (although this is more of a C++-style-C-style cast. (unsigned) would have been the C-cast. But still bad). But in this situation it should be safe and for use in an example more readable. btw. Please fix either the size of your code or the margins of your blog. You use only half the screen width but I still have to scroll sideways in the code listing.
- mikeash 14y agoHow can a C-style cast from char to unsigned possibly be "less safe", and how could a different style of cast be more safe?
- daivd 14y agoIn this case it obviously doesn't matter, but in the general case it is better to be explicit on which type of cast you are doing. That way the compiler can statically stop you from doing stupid things. Read the link I gave.