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: Fred Kiefer
Subject: Re: How to know the geometry of a string on the screen ?
Date: Wed, 1 Nov 2017 18:12:54 +0100

> 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 


reply via email to

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