Alex Rivera | Logout

Tool for finding C-style Casts

Asked 2010-04-07T14:12:14.200
35

Does anyone know of a tool that I can use to find explicit C-style casts in code? I am refactoring some C++ code and want to replace C-style casts where ever possible.

An example C-style cast would be:

Foo foo = (Foo) bar;

In contrast examples of C++ style casts would be:

Foo foo = static_cast<Foo>(bar);
Foo foo = reinterpret_cast<Foo>(bar);
Foo foo = const_cast<Foo>(bar);
c++ c
Edit
Report

3 Answers

37

If you're using gcc/g++, just enable a warning for C-style casts:

g++ -Wold-style-cast ...
answered 2010-04-07T14:59:14.113
0

If you use some kind of hungarian style notation (e.g. iInteger, pPointer etc.) then you can search for e.g. )p and ) p and so on.

It should be possible to find all those places in reasonable time even for a large code base.

answered 2010-04-07T14:21:22.710
-1

I used this regular expression in Visual Studio (2010) Find in files search box: :i\):i

Thanks to sth for the inspiration (his post)

answered 2013-04-25T14:35:56.950

Your Answer