c style covert and c++ style
来源:互联网 发布:ubuntu install go 编辑:程序博客网 时间:2024/06/04 18:49
1down vote
In short:
static_cast<>()
gives you a compile time checking ability, C-Style cast doesn't.static_cast<>()
is more readable and can be spotted easily anywhere inside a C++ source code, C_Style cast is'nt.- Intentions are conveyed much better using C++ casts.
More Explanation:
The static cast performs conversions between compatible types. It is similar to the C-style cast, but is more restrictive. For example, the C-style cast would allow an integer pointer to point to a char.
char c = 10; // 1 byteint *p = (int*)&c; // 4 bytes
Since this results in a 4-byte pointer pointing to 1 byte of allocated memory, writing to this pointer will either cause a run-time error or will overwrite some adjacent memory.
*p = 5; // run-time error: stack corruption
In contrast to the C-style cast, the static cast will allow the compiler to check that the pointer and pointee data types are compatible, which allows the programmer to catch this incorrect pointer assignment during compilation.
int *q = static_cast<int*>(&c); // compile-time error
You can also check this page on more explanation on C++ casts : Click Here
- c style covert and c++ style
- C style字符串
- Objective-c Code Style
- comment style in C
- C style字符串
- C style字符串
- objective-c code style
- Google-C++-style-headerfile
- 《Recommended C Style and Coding Standards》学习总结
- cast between Objective-C and Core Foundation-style objects
- C & C++ Programming Style Guidlines
- C#-continuation-passing style(CPS)
- Objective-C Coding Style Guidelines
- c-style string 的区别
- reverse a C-Style String
- Google Objective-C Style Guide
- emacs使用google-c-style
- Objective-c coding style guide
- C++中explicit关键字的作用
- iOS Autorelease Runloop
- 获取API函数入口处前后5字节数据
- Android中Camera架构
- 自动化测试工具QTP:维护对象库、获取对象属性、智能识别、参数化若干问题
- c style covert and c++ style
- Unity3d的Transform结构图
- 对android:gravity的理解
- Byte[]、Image、Bitmap 之间的相互转换
- 测试自己的系统是大端还是小端
- Win7下安装Flash Builder时,总是安装进度到1%就失败的问题
- POJ_1511_Invitation Cards(SPFA)
- Android Intent 用法全面总结
- find+grep查找文件,并显示文件名