tags:

views:

77

answers:

1

Hi,

Is there some tool that can automatically convert the following c style code

A *a = b;

to

A *a = (A*)b;

Thanks, James

+2  A: 

Assuming this is to eliminate compiler errors, I would probably write one myself. Run the compiler on the source, and redirect error messages to a file. Filter out the errors where it complains about the type. For example, in gcc, they will look like this:

a.cc:3: error: invalid conversion from ‘int’ to ‘int*’

This gives you all you need: file and line number, as well as the type you need to cast to (i.e. int*). Find a likely place in the line to insert the cast (i.e. after the = character, or after the return statement), and try again. Keep track of the lines that you already edited, and skip them for human intervention.

Martin v. Löwis
Yea that's a good suggestion. I'm looking for some preexisting tool at the moment, though, before I go and roll my own.
jameszhao00