discuss-gnustep
[Top][All Lists]
Advanced

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

Re: How to know the geometry of a string on the screen ?


From: Bertrand Gmail
Subject: Re: How to know the geometry of a string on the screen ?
Date: Thu, 2 Nov 2017 20:05:41 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

Le 01/11/2017 à 18:12, Fred Kiefer a écrit :
Am 29.10.2017 um 12:58 schrieb Bertrand Gmail <bertrand.dekoninck@gmail.com>:

Moreover, I could put "string.size" instead of "[string size]". But I wonder if 
it ist an Objc-2 feature and  if it will compile with gcc and it's libobjc.

I use somewhere else in my code :

"screenFrame = [[NSScreen mainScreen] frame];
  screenSize = screenFrame.size;"

Is it also Objc-2 only ?
I ask because I wanted to be Objc-1 only and I tried "[screenFrame size]" 
instead but it doesn't work : I've got this message from the compiler :

"error: bad receiver type 'NSRect' (aka 'struct _NSRect')
  screenSize = [screenFrame size];"

That's not a big deal because I already I had another more complicated code for 
this borrowed from the internet. It's my will to understand what's going wrong 
there.
You are confusing two things here and it isn’t even your fault. The designers 
of ObjC-2 are to blame.

In the first case „string.size" means you are sending the message "size" to the 
object „string“ and this is just a different way to writing „[string size]“.
In the second case „sceenFrame.size“ means you are accessing the element „size“ 
of the structure „screenFrame“. This is a pure C operation.

ObjC-2 uses the same notation for these two complete different operations and 
this indeed confusing. That is the reason why we in the GNUstep project prefer 
to use the old fashioned [] notation for message sending.

Hope this helps,
Fred
Thanks a lot for your explanation. I think I should look at the documentation to know if something is an objc object or a pure C structure from now.

Bertrand.





reply via email to

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