There is no difference in terms of generated assembly code between static_cast<double> (a)
and (double) a
. The key advantage of cast notation, (type_id) cast_expression
, is that it is more flexible. In one situation it might be the equivalent of a const_cast
, in another, a static_cast
, in yet another, a dynamic_cast
, in yet another, a combination of const_cast
and static_cast
(or dynamic_cast
).
This strength is also a weakness. Cast notation means different things in different places. Another disadvantage is that it is very easy to find xxx_cast<type_id> (cast_expression)
. Just search for _cast
. It is very hard to find expressions that use cast notation.
a
is anint
,static_cast<double>(a)
,(double)a
, anddouble(a)
are all semantically identical. The differences become evident whena
is some other non-scalar type, or isconst
orvolatile
, etc. – Cartloaddouble(a)
be a bit (but insignificant) slower at compiling because it will first try to match aconst_cast
? – Trinary