https://en.cppreference.com/w/cpp/language/explicit_cast Basically, it is equivalent to a C-style cast (int) d, which does consider static_cast, but could also do a reinterpret_cast if valid. Answer from marko312 on reddit.com
🌐
Reddit
reddit.com › r/cpp_questions › is `static_cast(y)` the same as `x(y)` for simple data types like `int` and `double`?
r/cpp_questions on Reddit: Is `static_cast<X>(y)` the same as `X(y)` for simple data types like `int` and `double`?
August 11, 2020 -

Say I had the lines:

double d = 1.1;
auto a = int(d);
auto b = static_cast<int>(d);

I understand that I'm doing a cast of a double to an in for the creation of variable b, but is that also happening as well for the creation of a? If I can use is as a shorthand for doing static casts, I'd love to. But if that constructor style variable creation isn't actually doing a static cast, I'd like to know too.

EDIT:

I would say this is my favourite answer of the bunch: https://www.reddit.com/r/cpp_questions/comments/i76d6e/is_static_castxy_the_same_as_xy_for_simple_data/g119fnu/

🌐
TutorialsPoint
tutorialspoint.com › article › why-use-static-cast-int-x-instead-of-int-x-in-cplusplus
Why use static_cast(x) instead of (int)x in C++?
February 11, 2020 - The (int)x is C-style typecasting, where static_cast<int>(x) is used in C++. This static_cast<>() gives a compile-time checking facility, but the C-style casting does not support that. This static_cast<>() can be spotted anywhere inside a C++ code.
Discussions

c++ - Why use static_cast (x) instead of (T)x or T(x)? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I've heard that the static_cast function should be preferred to C-style or simple function-style casting. Is this true? More on stackoverflow.com
🌐 stackoverflow.com
March 14, 2017
int vs. typecast - C++ Forum
Code/IDE output below. The tutorial was extolling the virtues of using static_cast over integer assignment in converting integer to ASCII. I have both methods listed below. I want to know why the second is "better" then the first. More on cplusplus.com
🌐 cplusplus.com
April 17, 2025
static_cast vs (int).... - General and Gameplay Programming - Forums - GameDev.net
Ok, I've been thinking on this a while, wondering if there is any major difference between: void* pointer = static_cast(pointer); void* pointer = (int)malloc(8… More on gamedev.net
🌐 gamedev.net
February 2, 2026
static_cast vs (int)....
If you're using c++ I'd use static_cast or one of the other C++ casting type. static_cast is a little smarter then C style casts. It will do some simple type checking. Any help I can get the compiler to do for me is good in my book. C style casts are completely ignorant. More on gamedev.net
🌐 gamedev.net
6
March 1, 2025
Top answer
1 of 9
765

The main reason is that classic C casts make no distinction between what we call static_cast<>(), reinterpret_cast<>(), const_cast<>(), and dynamic_cast<>(). These four things are completely different.

A static_cast<>() is usually safe. There is a valid conversion in the language, or an appropriate constructor that makes it possible. The only time it's a bit risky is when you cast down to an inherited class; you must make sure that the object is actually the descendant that you claim it is, by means external to the language (like a flag in the object). A dynamic_cast<>() is safe as long as the result is checked (pointer) or a possible exception is taken into account (reference).

A reinterpret_cast<>() (or a const_cast<>()) on the other hand is always dangerous. You tell the compiler: "trust me: I know this doesn't look like a foo (this looks as if it isn't mutable), but it is".

The first problem is that it's almost impossible to tell which one will occur in a C-style cast without looking at large and disperse pieces of code and knowing all the rules.

Let's assume these:

class CDerivedClass : public CMyBase {...};
class CMyOtherStuff {...} ;

CMyBase  *pSomething; // filled somewhere

Now, these two are compiled the same way:

CDerivedClass *pMyObject;
pMyObject = static_cast<CDerivedClass*>(pSomething); // Safe; as long as we checked

pMyObject = (CDerivedClass*)(pSomething); // Same as static_cast<>
                                     // Safe; as long as we checked
                                     // but harder to read

However, let's see this almost identical code:

CMyOtherStuff *pOther;
pOther = static_cast<CMyOtherStuff*>(pSomething); // Compiler error: Can't convert

pOther = (CMyOtherStuff*)(pSomething);            // No compiler error.
                                                  // Same as reinterpret_cast<>
                                                  // and it's wrong!!!

As you can see, there is no easy way to distinguish between the two situations without knowing a lot about all the classes involved.

The second problem is that the C-style casts are too hard to locate. In complex expressions it can be very hard to see C-style casts. It is virtually impossible to write an automated tool that needs to locate C-style casts (for example a search tool) without a full blown C++ compiler front-end. On the other hand, it's easy to search for "static_cast<" or "reinterpret_cast<".

pOther = reinterpret_cast<CMyOtherStuff*>(pSomething);
      // No compiler error.
      // but the presence of a reinterpret_cast<> is 
      // like a Siren with Red Flashing Lights in your code.
      // The mere typing of it should cause you to feel VERY uncomfortable.

That means that, not only are C-style casts more dangerous, but it's a lot harder to find them all to make sure that they are correct.

2 of 9
132

One pragmatic tip: you can search easily for the static_cast keyword in your source code if you plan to tidy up the project.

🌐
INFN
fe.infn.it › u › paterno › Geant4_tutorial › C++ resources › static_cast.pdf pdf
Why use static_cast<int>(x) instead of (int)x?
July 30, 2019 - Why use static_cast<int>(x) instead of (int)x? The main reason is that classic C casts make no distinction between what we call static_cast<>(), reinterpret_cast<>(), const_cast<>(), and dynamic_cast<>(). These four things are completely · different. A static_cast<>() is usually safe.
🌐
Cplusplus
cplusplus.com › forum › general › 171720
int vs. typecast - C++ Forum
April 17, 2025 - > I want to know why the second is "better" then the first That static_cast<int>(c) is 'better' than int(c) or +c is a matter of opinion. For the record, I do not agree with it.
🌐
Learn C++
learncpp.com › cpp-tutorial › introduction-to-type-conversion-and-static_cast
4.12 — Introduction to type conversion and static_cast – Learn C++
October 21, 2021 - It’s worth noting that the argument to static_cast evaluates as an expression. When we pass in a variable, that variable is evaluated to produce its value, and that value is then converted to the new type. The variable itself is not affected by casting its value to a new type. In the above case, variable ch is still a char, and still holds the same value even after we’ve cast its value to an int.
Find elsewhere
🌐
GameDev.net
gamedev.net › home › forums › programming › general and gameplay programming › static_cast vs (int)....
static_cast vs (int).... - General and Gameplay Programming - Forums - GameDev.net
February 2, 2026 - A c-style cast attempts to change one object type into another [through use of inbuilt conversion routines, or the conversion routines that you build into your objects through things like 'operator int()'] The static casts can also do this, but don't like casting pointers in general, unless there is an inbuilt conversion or one object is derived from the other.
🌐
TutorialsPoint
tutorialspoint.com › article › what-is-the-difference-between-static-cast-and-c-style-casting
What is the difference between static_cast<> and C style casting?
July 30, 2019 - Here we will see what are the differences between static_cast and normal C style cast. The normal cast like (int)x is C style typecasting where static_cast (x) is used in C++.
🌐
Cppreference
en.cppreference.com › w › cpp › language › static_cast.html
static_cast conversion - cppreference.com
August 18, 2024 - one is a standard-layout class object and the other is the first non-static data member of that object or any base class subobject of that object, or · there exists an object c such that a and c are pointer-interconvertible, and c and b are pointer-interconvertible.
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › static_cast-in-cpp
static_cast in C++ - GeeksforGeeks
July 11, 2025 - This is the simplest type of cast that can be used. It is a compile-time cast. It does things like implicit conversions between types (such as int to float, or pointer to void*), and it can also call explicit conversion functions. ... The return value of static_cast will be of dest_type.
🌐
GameDev.net
gamedev.net › forums › topic › 356627-static_cast-vs-int › 3339599
static_cast vs (int).... - General and Gameplay Programming - GameDev.net
March 1, 2025 - A c-style cast attempts to change one object type into another [through use of inbuilt conversion routines, or the conversion routines that you build into your objects through things like 'operator int()'] The static casts can also do this, but don't like casting pointers in general, unless there is an inbuilt conversion or one object is derived from the other.
🌐
GeeksforGeeks
geeksforgeeks.org › static_cast-in-c-type-casting-operators
static_cast in C++ | Type Casting operators - GeeksforGeeks
January 5, 2023 - This means that even if you think you can some how typecast a particular object int another but its illegal, static_cast will not allow you to do this.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › cpp › static-cast-operator
static_cast Operator | Microsoft Learn
October 21, 2021 - In general you use static_cast when you want to convert numeric data types such as enums to ints or ints to floats, and you are certain of the data types involved in the conversion. static_cast conversions are not as safe as dynamic_cast ...
🌐
GameDev.net
gamedev.net › forums › topic › 356627-static_cast-vs-int › 3339597
static_cast vs (int).... - General and Gameplay Programming - GameDev.net
April 17, 2019 - A c-style cast attempts to change one object type into another [through use of inbuilt conversion routines, or the conversion routines that you build into your objects through things like 'operator int()'] The static casts can also do this, but don't like casting pointers in general, unless there is an inbuilt conversion or one object is derived from the other.
Top answer
1 of 9
65

First, understand that those lines are not equivalent.

int* anInt = (int*)aFloat; // is equivalent to

int* anInt = reinterpret_cast<int*>(aFloat); 

What is happening here is that the programmer is asking the compiler to do whatever it can to make the cast.

The difference is important because using static_cast will only ask for a base type that is "safe" to convert to, where reinterpret_cast will convert to anything, possibly by just mapping the wanted memory layout over the memory of the given object.

So, as the "filter" is not the same, using a specific cast is more clear and safe than using the C cast. If you rely on the compiler (or runtime implementation if you use dynamic_cast) to tell you where you did something wrong, by avoid using C cast and reinterepret_cast.

Now that this is more clear, there is another thing: static_cast, reinterpret_cast, const_cast and dynamic_cast are easier to search for.

And the ultimate point: they are ugly. That's wanted. Potentially buggy code, code smells, obvious "tricks" that might generate bugs, are easier to track when it's associated with ugly look. Bad code should be ugly.

That's "by design". And that allows the developer to know where he could have done things better (by totally avoiding casts, if not really needed) and where it's fine but it's "documented" in the code by "marking" it as ugly.

A secondary reason for introducing the new-style cast was that C-style casts are very hard to spot in a program. For example, you can't conveniently search for casts using an ordinary editor or word processor. This near-invisibility of C-style casts is especially unfortunate because they are so potentially damaging. An ugly operation should have an ugly syntactic form. That observation was part of the reason for choosing the syntax for the new-style casts. A further reason was for the new-style casts to match the template notation, so that programmers can write their own casts, especially run-time checked casts.

Maybe, because static_cast is so ugly and so relatively hard to type, you're more likely to think twice before using one? That would be good, because casts really are mostly avoidable in modern C++.

Source: Bjarne Stroustrup (C++ creator)

2 of 9
41

C++ casts are more restrictive (so express your intent better and make code review easier, etc.). They're also much easier to search for, if you ever need to.

🌐
Wikipedia
en.wikipedia.org › wiki › Static_cast
static_cast - Wikipedia
September 1, 2025 - In the C++ programming language, static_cast is an operator that performs an explicit type conversion. ... The type parameter must be a data type to which object can be converted via a known method, whether it be a builtin or a cast. The type can be a reference or an enumerator.
🌐
Quora
quora.com › Would-it-be-safe-if-we-convert-all-static_cast-int32_t-to-be-just-static_-cast-int-in-a-large-C-Unicode-source
Would it be safe if we convert all static_cast<int32_t>() to be just static_ cast<int>() in a large C++ Unicode source?
On most modern 64‑bit Linux/macOS with common ABIs, int is 32 bits and int32_t is typedef’d to int. Replacing casts is safe for value range and representation. On a platform where the type alias relation is confirmed (e.g., comp ... Short answer Converting all static_castwzxhzdk:0() to static_castwzxhzdk:1() is not universally safe.
🌐
Learn C++
learncpp.com › cpp-tutorial › explicit-type-conversion-casting-and-static-cast
10.6 — Explicit type conversion (casting) and static_cast – Learn C++
March 4, 2025 - First, static_cast provides compile-time type checking. If we try to convert a value to a type and the compiler doesn’t know how to perform that conversion, we will get a compilation error. // a C-style string literal can't be converted to an int, so the following is an invalid conversion int x { static_cast<int>("Hello") }; // invalid: will produce compilation error