[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Have you ever seen a compiler error message like this?
From: |
Benedikt Stefansson |
Subject: |
Re: Have you ever seen a compiler error message like this? |
Date: |
Thu, 06 Nov 1997 22:51:23 -0800 |
Paul Johnson wrote:
> -(dimarray)makeProp: (dimarray) x {
>
> newpos[0]= x[0] + 1; //this would be embellished once I understood
> newpos[1]= x[1] + 1; //the passing of values.
> return newpos;}
>
C arrays are a bitch to figure out at first, because the array name is a
pointer.
You also have to be careful when passing references back and forth to make a
distinction between variables that are declared within a method, and thus
deallocated once the method has finished, and instance variables. From your
code it
isn't clear where newpos was declared. If newpos is an instance variable you
could
change the method to (note the pointer reference to x):
-makeProp: (dimarray *) x {
newpos[0]= x[0] + 1; //this would be embellished once I understood
newpos[1]= x[1] + 1; //the passing of values.
return self;
}
If newpos is not an instance variable of this object you either have to pass the
pointer in the method call or allocate memory for newpos in the method. So you
can
either change the method interface to:
-makeProp: (dimarray *) in to: (dimmarray *) out {
out[0]=in[0]+1;
out[1]=in[1]+1;
return self;
}
where you have to have allocated memory for out beforehand, or you allocate the
memory directly in the method:
-(dimarray *) makeProp: (dimarray *) x {
dimarray * newpos;
newpos=calloc(2,sizeof(dimarray));
newpos[0]= x[0] + 1;
newpos[1]= x[1] + 1;
return newpos;
}
Regards,
-Benedikt
--
----------------
Benedikt Stefansson address@hidden
Department of Economics, UCLA Fax. (310) 825-9528
Los Angeles, CA 90095-1477 Tel. (310) 825-4126
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
==================================