Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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



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: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >How does -getLineStart:end:contentsEnd:forRange work ? (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.