Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Possible Duplicate:
How to find (and replace) all old C-style data type casts in my C++ source 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)

like image 667
shuttle87 Avatar asked May 07 '11 18:05

shuttle87


1 Answers

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.

like image 127
Marc Mutz - mmutz Avatar answered Sep 19 '22 18:09

Marc Mutz - mmutz