[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sharing variables and inline functions
From: |
Axel von Kamp |
Subject: |
Re: Sharing variables and inline functions |
Date: |
Thu, 04 Mar 1999 15:06:58 +0000 |
Fabio Mascelloni wrote:
> Axel von Kamp wrote:
>
> > I've also been thinking about how to efficiently gain read access to
> > instance
> > variables without declaring them as @public. My idea (inspired by what
> > C++ does) is that, since in Objective C you can still use functions and gcc
> > supports inline functions (which is not ANSI standard), to use inline
> > functions for access. I have edited the example below to illustrate what I'm
> > talking about
> >
> >
> > inline int getShared (ModelSwarm *this);
> >
> >
> >
> > inline int getShared (ModelSwarm *this)
> > {
> > return this-> shared;
corrected
>
> > }
> >
> >
> > int myInt;
> > myInt= getShared (modelSwarm);
> >
>
> That's right when you want to get a variable that's not a pointer.If "shared"
> was a a pointer, the method would return a reference
> to a protected variable,would't it?
Well, yes, it would return the pointer. But the pointer doesn't neccessarily
have to
point to a protected variable.
> >
> > This should (?; I'm no compiler expert, so anybody with more technical
> > knowledge please comment on this) be as efficient as using a @public
> > instance
> > variable without the drawback that @public instance variables can also be
> > written to.
>
> > (Furthermore, @public instance variables are not considered to begood style
> > in
> > OO languages.)
>
> I don'care much about style when I've only two months to learn
> Objective-C,Swarm
> and make a complex simulation ;-)
>
> What about implementing a separate generic Objective-C class "CommonClass"
> whose
> interface contains all the public members?
That's what I'm actually using to store the parameters for my simulation. It is
very
convenient because I don't need to write a function/message for each parameter
but
can use the -> operator as you suggest below.
>
> The values of these members would be set by the CommonClass instance through
> methods defined in the class,and they would be read directly by each other
> Swarm-object accessing them with the --> operator.
-Axel
==================================
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.