Pass-by value… warning (was: NSTextField fieldeditor subclass example? (and an unrelated other inquiry))
Pass-by value… warning (was: NSTextField fieldeditor subclass example? (and an unrelated other inquiry))
- Subject: Pass-by value… warning (was: NSTextField fieldeditor subclass example? (and an unrelated other inquiry))
- From: vincent habchi <email@hidden>
- Date: Wed, 7 Jul 2010 07:59:38 +0200
Hi!
Le 6 juil. 2010 à 21:59, Matt Neuburg a écrit :
> On Tue, 6 Jul 2010 20:31:06 +0200, vincent habchi <email@hidden> said:
>> BTW, another unrelated question. I have a method that takes an NSPoint as an
> argument. I call it this way:
>>
>> [foo point:NSMakePoint(x, y)]
>>
>> and get an analyzer warning: "Pass-by-value argument in function call is
> undefined".
>
> How about passing an NSValue? Surely valueWithPoint: must be good for
> something... :) m.
It appears the warning should be read: "The variable you pass to NSMakePoint is undefined". The real code looks like this:
- (void)drawPoint:(CGContextRef)ctx origin:(CGPoint)origin dimension:(int)dim data:(char **)data {
double pt [dim];
for (int i = 0 ; i < dim ; i ++) {
memcpy (& (pt [i]), * data, sizeof (double));
* data += sizeof (double);
}
NSPoint point = [displayController mapToLayerCoordinates:NSMakePoint(pt [0], pt [1])];
The analyzer does not figure out that the pt array gets initialized through the loop by copying values directly from a chunk of memory, and spits out the warning about pt [•] not being defined. Maybe I should report this to the LLVM team?
Vincent
PS : Note that the (char **) may seem a bit clumsy, but the chunk of memory contains different informations, not only double. I will probably rewrite it thus:
- (void)drawPoint:(CGContextRef)ctx origin:(CGPoint)origin dimension:(int)dim data:(double **)data {
double pt [dim];
for (int i = 0 ; i < dim ; i ++, *data ++) {
memcpy (& (pt [i]), * data, sizeof (double));
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden