• 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: How does -getLineStart:end:contentsEnd:forRange work ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How does -getLineStart:end:contentsEnd:forRange work ?


  • Subject: Re: How does -getLineStart:end:contentsEnd:forRange work ?
  • From: Jonathon Mah <email@hidden>
  • Date: Fri, 30 Jun 2006 00:40:36 +0930

Hi Ewan,

On 2006-06-29, at 23:44, email@hidden wrote:

Just to gain familiarity with the - getLineStart:end:contentsEnd:forRange, I tried the following fantasy code :

unsigned* startIndex=47;

This will make the startIndex variable a memory address which potentially points to an unsigned int. It declares a holder for the address only, not for the unsigned. Initializing it to 47 makes it point to memory address 47 (probably invalid and not an unsigned).


The by-reference arguments of the -getLineStart:... method are "unsigned *" -- you need to provide an address of an unsigned int where the method can store the number. To do that, you can declare some variables normally, and use the C address-of operator (&) to get their addresses:

unsigned startIndex, lineEndIndex, contentsEndIndex;
[z1 getLineStart:&startIndex
             end:&lineEndIndex
     contentsEnd:&contentsEndIndex
        forRange:(...)];

Your original code was passing in 47 for the startIndex pointer, meaning that the method was trying to write over whatever was at memory address 47, causing an exception and crashing the app.



Jonathon Mah
email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >How does -getLineStart:end:contentsEnd:forRange work ? (From: email@hidden)

  • Prev by Date: RE: Help needed in NSSplitView
  • Next by Date: Re: Is there another way to do performSelectorOnMainThread?
  • Previous by thread: How does -getLineStart:end:contentsEnd:forRange work ?
  • Next by thread: Re: How does -getLineStart:end:contentsEnd:forRange work ?
  • Index(es):
    • Date
    • Thread