Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 32053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:42:06+00:00 2026-05-10T13:42:06+00:00

A question related to Regular cast vs. static_cast vs. dynamic_cast : What cast syntax

  • 0

A question related to Regular cast vs. static_cast vs. dynamic_cast:

What cast syntax style do you prefer in C++?

  • C-style cast syntax: (int)foo
  • C++-style cast syntax: static_cast<int>(foo)
  • constructor syntax: int(foo)

They may not translate to exactly the same instructions (do they?) but their effect should be the same (right?).

If you’re just casting between the built-in numeric types, I find C++-style cast syntax too verbose. As a former Java coder I tend to use C-style cast syntax instead, but my local C++ guru insists on using constructor syntax.

What do you think?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:42:07+00:00Added an answer on May 10, 2026 at 1:42 pm

    It’s best practice never to use C-style casts for three main reasons:

    • as already mentioned, no checking is performed here. The programmer simply cannot know which of the various casts is used which weakens strong typing
    • the new casts are intentionally visually striking. Since casts often reveal a weakness in the code, it’s argued that making casts visible in the code is a good thing.
    • this is especially true if searching for casts with an automated tool. Finding C-style casts reliably is nearly impossible.

    As palm3D noted:

    I find C++-style cast syntax too verbose.

    This is intentional, for the reasons given above.

    The constructor syntax (official name: function-style cast) is semantically the same as the C-style cast and should be avoided as well (except for variable initializations on declaration), for the same reasons. It is debatable whether this should be true even for types that define custom constructors but in Effective C++, Meyers argues that even in those cases you should refrain from using them. To illustrate:

    void f(auto_ptr<int> x);  f(static_cast<auto_ptr<int> >(new int(5))); // GOOD f(auto_ptr<int>(new int(5));                // BAD 

    The static_cast here will actually call the auto_ptr constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is related to (but perhaps not quite the same as): Does Django
I have a question related to how relative paths are interpreted in various environments
I have a simple question related to one-line programming. First an example: function test(a)
(See related question: How do I report an error midway through a chunked http
A related question to one I asked earlier ... Just checking on something: Should
My question is related to the command pattern, where we have the following abstraction
In a related question I asked about creating a generic container. Using polymorphic templates
In a related question , my team is about to (hopefully) start using LINQ,
This question is related to another question which I asked yesterday! List all links
related question: Case insensitive replace What's the best way to do a case insensitive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.