473,388 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

static_cast versus C-style type cast

Is there a difference between a static_cast and an C-style type cast?

In other words, is there a difference between...

int a;
unsigned b = static_cast<unsigned>(a); // static_cast
unsigned c = (unsigned)(a); // C-style cast

Jul 19 '05 #1
1 20670
Dave Rahardja wrote:
Is there a difference between a static_cast and an C-style type cast?
Yes.
In other words, is there a difference between...

int a;
unsigned b = static_cast<unsigned>(a); // static_cast
unsigned c = (unsigned)(a); // C-style cast


No.
A static_cast is more restrictive than a C style cast. The latter will
do the same as any combination of static_cast, const_cast and
reinterpret_cast that is necessary for the requested convertion.

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Wenjie | last post by:
Hello, I have a class B to mediate/isolate between implementation and their users (like used in an abstract factory class pattern): // B.h class B { static B* getImpl(); static void...
4
by: Jim West | last post by:
Both int a; std::complex<float> b; std::complex<float> c = static_cast<float>(a)*b; and int a; std::complex<float> b;
13
by: GianGuz | last post by:
Everyone knows about the complex and cpu-expensive procedures taken by dynamic_cast to find the right function call in a virtual classes hierarchy. The question I would to rise is when...
6
by: nin234ATIyahoo.com | last post by:
Hi all I have a logger class and facing the following issue enum eErrLvl { eLOG_DEBUG_5 = 1, eLOG_DEBUG_4, eLOG_DEBUG_3, eLOG_DEBUG_2, eLOG_DEBUG_1,
6
by: bonham | last post by:
i m a beginner in C++. I have some questions: what is static_cast<unsigned>? i saw someone use static_cast<unsigned> and static_cast<unsigned char> together. why? e.g....
6
by: Dave Rahardja | last post by:
Is it safe to use static_cast to downcast from a virtual base class? For example, class V {}; class A: public virtual V {}; class B: public virtual V {}; class C: public A, public B; void...
24
by: Rahul | last post by:
Hi, I have a class A : public B {...member functions......data members}; and am doing the following A *p=new A(); void *p=static_cast<void *>(p); factory_instance->process(p);
11
by: Bo Peng | last post by:
Dear C++ experts, I need to store and retrieve a meta information that can be int or double. The program would be significantly simpler if I can handle two types uniformly. Right now, I am using...
10
by: Jim Langston | last post by:
Is the following well defined? size_t IntVal = 65537; unsigned short Length; if ( IntVal static_cast<unsigned short>( -1 ) ) { std::cout << "Value too long to fit in a short" << std::endl;...
3
by: Rahul | last post by:
Hi, Everywhere I read that static_cast<only work fine for the conversion which are implicitly allowed by the compiler hence the following does not work int *i; double *d; d = i; ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.