swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Return pointer to array: not possible?


From: Axel von Kamp
Subject: Re: Return pointer to array: not possible?
Date: Thu, 01 Apr 1999 18:12:47 +0100

Paul E. Johnson wrote:

> I'm just fiddling around, really, learning ways to torture C and
> Objective-C. But I figured some of you with actual computer training
> might save me a bit of trouble.
>
> Suppose you have a C array of objects, declared like so
>
> id attribute[10];
>
> How can I return that when another agent wants the attribute vector?

return attribute;

It's as simple as that. Your method definition then would look like:

-(id *)getAttributeArray
{
   return attribute;
}

> I figure there has to be a better way, such creating a pointer to the
> array, and returning that.  But I can't get it to work, can't find a
> clear example in any of the C books I have.

The name of a C vector is synonym to the address of its first element. Thus
it can be used as pointer to that vector.
Strange that none of your C books mentions this...


                  ==================================
   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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]