Is T (x) great?

Below is the cast:

int foo = (int) somefloat; 

However, is it considered cast?

 int foo = int( somefloat ); 

More importantly, if there is a difference between the two, is the resulting compiled code different?

+7
source share
3 answers

The second example is often called function style creation and was added in C ++, but there is no difference between them in terms of semantics / object code.

Here's a good explanation of the reason that function style styles were added:

What exactly is the purpose of C ++ in the style of functions?

+5
source

There is no difference in the results, however, only the first example can be used in C. In C ++, you can use both.

+2
source

Yes, this is also a throw. C ++ allows this casting style; C has only (type)expression formatting. They are equivalent.

+1
source

All Articles