Groups | Search | Server Info | Login | Register


Groups > comp.lang.objective-c > #277

Re: instance variables & properties

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From "Pascal J. Bourguignon" <pjb@informatimago.com>
Newsgroups comp.lang.objective-c
Subject Re: instance variables & properties
Date Tue, 26 Jul 2016 01:43:53 +0200
Organization Informatimago
Lines 48
Message-ID <878twpthae.fsf@kuiper.lan.informatimago.com> (permalink)
References <nn5rh0$rep$1@news.albasani.net>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Trace individual.net xvV8u9T/NDJEQQsz0/MMMQvtLVYNIjthVl1FQzGUdYFSBCbcCb
Cancel-Lock sha1:YjUyZWMxMjFhNmQ1ZWFhMmZjMWRkYzBkNmQ3YmViMWM5M2Q2NzlhZQ== sha1:9LDXF1FCSfT9u3zSWJp3Lbm8Sb8=
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg==
X-Accept-Language fr, es, en
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
Xref csiph.com comp.lang.objective-c:277

Show key headers only | View raw


Jon Rossen <jonr17@comcast.net> writes:

> I have a theoretical question on a situation where duplicate instance
> variables are created.  It's not something that is advised to do but I
> am wondering what is going on 'under the hood'.
>
> You declare two instance variables:
> {  int foo1, foo2 }
>
> You also set properties:
> @property int foo1, foo2;
>
> You *don't* use @synthesize, so auto synthesis is used; the
> properties' backing instance variables by default are set to _foo1 &
> _foo2.
>
> When building, you get a warning (that is to be expected I suppose):
> 'Autosynthesized property 'foo1' will use synthesized variable
> '_foo1', not existing instance variable 'foo1'.
>
> If you have methods that are accessing your instance variables, you
> don't get warnings or errors if you use either the synthesized
> instance variable (_foo1) or the existing intstance variable (foo1).
>
> So, what's going on here?  How is this not an out and out error rather
> than just a mere warning?

It's just that you have two instance variables, foo1 and _foo1.

Imagine that you wrote in C:

    struct {
       int foo1;
       int fool;
    } s;

and the C compiler would issue a warning: "your structure s contains two
fields named foo1 and fool and those names could easily be confused".
Do as you wish, but it might be a good idea to rename one of them.
The compile won't be confused by them but any human reader will probably
be.


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

Back to comp.lang.objective-c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

instance variables & properties Jon Rossen <jonr17@comcast.net> - 2016-07-25 13:06 -0700
  Re: instance variables & properties "Pascal J. Bourguignon" <pjb@informatimago.com> - 2016-07-26 01:43 +0200
    Re: instance variables & properties Jon Rossen <jonr17@comcast.net> - 2016-07-25 19:05 -0700
      Re: instance variables & properties "Pascal J. Bourguignon" <pjb@informatimago.com> - 2016-07-26 22:56 +0200
        Re: instance variables & properties Jon Rossen <jonr17@comcast.net> - 2016-07-26 17:40 -0700

csiph-web