[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Wierd Warning
From: |
Frank D. Engel, Jr. |
Subject: |
Re: Wierd Warning |
Date: |
Wed, 19 Mar 2003 05:20:48 -0800 (PST) |
> Now, look at the signature of the cString method in NSString.h:
> - (const char*) cString;
> the 'const' here means that the returned string MUST NOT be modified.
Exactly, therefor the (char *) cast... since I do modify it later on.
>> Therefore, you should declare pat as:
>> const char* pat=[pattern cString];
>> and you should declare:
>> BOOL initPattern(const char** pattern,BOOL flag)
>> In initPattern, you cannot modify the content of the memory
>>block
>> pointed by (*pattern) (that is, (*pattern)[i]). You can
>>still
>> allocate a new memory block and return it thru (*pattern).
>
>Unfortunately, that's not really an option, as pattern will be passed
>to
>several other functions from initPattern, which all will modify it.
Uh... you seem to miss the point here. The whole explanation for
returning a CONSTant pointer is that the caller should NEVER change the
data it points to. Casting to a non-CONST pointer allows assignment to
the mutable-type pointer, but it still results in potentially changing
the data that the CONSTant pointer pointed to, which you should not be
doing. Instead, you should make a COPY of that data, and work with the
COPY.
The warning you recieved should have pointed to the earlier line, where
you made the cast; that is much more likely to be a problem.
=====
=======
Frank D. Engel, Jr.
Modify the equilibrium of the vertically-oriented particle decelerator to
result in the reestablishment of its resistance to counterproductive
atmospheric penetration.
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
- Re: Wierd Warning,
Frank D. Engel, Jr. <=