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

Ask A Question

Stats

  • Questions 157k
  • Answers 157k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer When you write machine language using op-codes e.g .. MOV… May 12, 2026 at 11:02 am
  • Editorial Team
    Editorial Team added an answer Need to use namespace System.Web.Abstractions In particular, take a HttpResponseBase… May 12, 2026 at 11:02 am
  • Editorial Team
    Editorial Team added an answer I've checked the documentation, and no directly, but with a… May 12, 2026 at 11:02 am

Related Questions

Suppose you have a list of acronym's that define a value (ex. AB1,DE2,CC3) and
Seeing various locking related question and (almost) always finding the 'loop because of spurious
By Windows PC displays, I am not referring to Windows CE, or handhelds, etc.
I want to match a portion of a string using a regular expression and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.