开发者

Is there a way of disabling the old c style casts in c++ [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to find (and replace) all old C-style data type casts in my C++ sou开发者_JS百科rce code?

I'm currently refactoring some old code and the project I am working on has a policy of only using the new c++ style casts. I'm trying to make sure that I don't miss any but currently the approach I'm taking is quite crude so I'm wondering if there is any way of making the old c style casts not compile in a c++ project? (or at least give a compiler warning if this is not possible)


If you use GCC, add -Wold-style-cast to the command line. That gives warnings, not errors, but you can always add -Werror, which turns warnings (all warnings) into errors.

As for other compilers, it seems no other compiler has such a warning option.

But that doesn't really matter: GCC is Free Software, and available on practically anything that can distinguish between zeros and ones. Just install it alongside your main compiler on your workstation, or into your continuous integration system, and use it for this task only. You will find that having two C++ compilers at hand is very convenient in general.

If installing GCC really isn't an option for you, you might want to take a peek at How to find (and replace) all old C-style data type casts in my C++ source code?, where some alternatives are discussed.


I recommend using this Perl script. Except for unusual conditions like (void**)&b.ComInterfaceCall it just appears to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜