[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getting rid of some compilation warnings
From: |
David Chisnall |
Subject: |
Re: getting rid of some compilation warnings |
Date: |
Sun, 14 Feb 2010 17:24:55 +0000 |
On 14 Feb 2010, at 17:06, Sebastian Reitenbach wrote:
> my guess is that obj is id, and the compiler doesn't know, which one to use.
> Is there a way to get rid of the warning?
Yes, use an explicit cast. In this case, the warning is not particularly
important because both are objects, so the same calling convention will apply
in both cases. That warning should be an error in most cases, however, because
it most commonly means 'this code will corrupt your stack'. Ether make obj and
NSString* or explicitly cast it to NSString* in the hasPrefix: message send,
like this:
if ([(NSString*)obj hasPrefix: @"\\"])
Actually, since you're just testing whether the leading character is '\\'
wouldn't it be better to say:
if ([obj charAtIndex: 0] == '\\')
This will fail if you empty strings, but you are already checking that the
string is not empty on the previous line, so you are doing about half a dozen
message sends to check whether two characters are equal.
David
-- Sent from my PDP-11