• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Finding typecasts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding typecasts


  • Subject: Re: Finding typecasts
  • From: Alastair Houghton <email@hidden>
  • Date: Tue, 18 Aug 2009 22:44:13 +0100

On 18 Aug 2009, at 22:09, 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.

Well... depends on the type of the integer that was in use, and on what the code does.


If you can reliably cover all of the code with test cases, then you could just build it in 64-bit mode and keep running it and fixing things until it no longer crashes (I'm assuming the casts are between pointers and 32-bit ints?)

If it's a big enough code base to justify it, you could use clang. I think you could knock together a tool to find them fairly quickly that way, actually; you'd want to subclass StmtVisitor, I think, and implement VisitCStyleCastExpr(), assuming the author used C-style casts. There's a bit of a learning curve there, to be sure, but my guess is that it'd actually be fairly easy when you got down to it. This might be useful:

  <http://amnoid.de/tmp/clangtut/tut.html>

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________
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


References: 
 >Finding typecasts (From: Mark Wagner <email@hidden>)

  • Prev by Date: Re: Finding typecasts
  • Next by Date: Re: Finding typecasts
  • Previous by thread: Re: Finding typecasts
  • Next by thread: Re: Finding typecasts
  • Index(es):
    • Date
    • Thread