Re: Finding typecasts
Re: Finding typecasts
- Subject: Re: Finding typecasts
- From: Quincey Morris <email@hidden>
- Date: Tue, 18 Aug 2009 14:51:15 -0700
On Aug 18, 2009, at 14:23, Dan White wrote:
Depends how he did it.
Did he cast ?
int foo = (int)(pointer) ;
or did he just "do it" implicitly ?
int foo = pointer + 1 ?
Strikes me that it would be very tough to automate finding either of
those.
You are going to have to examine every instance of every pointer to
isolate arithmetic operations.
The flexibility of C is definitely a two-edged sword (ouchies!)
On Aug 18, 2009, at 5:09 PM, Mark Wagner wrote:
How can I find every line of a C program where a pointer is cast to
an
integer, or vice-versa? I've got a library where the original author
treated pointers and integers as being the same thing, and I'm trying
to sort it out.
You're right that it's going to be tough to find such syntactical
"marker" constructs automatically. Beyond that, chances are that if
the original programmer also did nasty things mixing ints and
pointers, there are other problems that can't be recognized
syntactically.
The only safe way to fix the code is to rewrite it. (Simply *looking*
at it is too error-prone. There'd be one last problem that got
overlooked, and it might take days to find.)
A reasonable shortcut is to change the name of every pointer variable,
and change the name of every int variable that is or might be used as
a pointer (if there are any). [I mean, change the name in the
declaration, not change globally.] Then compile and get a *long* list
of errors and warnings. Then fix each error and warning individually.
That'd probably expose secondary errors and warnings. Rinse and repeat
until the compilation is error free. Then use Refactor, if desired, to
put the variable names back to whatever they should be. Painful though
this is, it's perhaps the only way to guarantee that each potentially
problematic source code line has been examined and corrected.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden