R
Rolf Magnus
Frederick said:Rolf Magnus posted:
There's an implicit conversion from int to size_t, so no cast is required.
Well, it's there, no matter if it's required or not.
When dealing with intrinsic types, the following are exactly equivalent:
short(5)
(short)5
Yes. Both are casts.
I myself prefer the latter, for two reasons:
(1) You can have types which consist of more than one word, e.g.
"unsigned short".
That's a good point.
(2) It resembles a cast.
Well, it is a cast, just like the first one.
I dislike the former because:
(1) It looks like the construction of a user-defined class type.
That's one reason why I like it. It uses built-in types more consistently
with classes by using the same syntax.
Btw: What do you do in a template, where the type might be either one?
(2) It doesn't resemble a cast at all.
Well, if you are used to the latter, because you know it from C, then you
might think like that. But basically, none of the two looks more "castish"
than the other.
(3) You can't use types which consist of more than one word.
Yes, that's a restriction that will hopefully be fixed some time.
One thing I like about it is that the value is in parenthesis, so in a
longer exression, it's easier to see which part of it is cast.