discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Warning with clang, error with gcc : attached files


From: Fred Kiefer
Subject: Re: Warning with clang, error with gcc : attached files
Date: Fri, 3 May 2019 15:05:28 +0200


On the road

Am 03.05.2019 um 14:42 schrieb Bertrand Dekoninck <address@hidden>:

> On 2019-05-03 14:01:43 +0200 David Chisnall <address@hidden> wrote:
> 
>>> On 03/05/2019 12:39, Bertrand Dekoninck wrote:
>>>   SEL aSelector = @selector(themeControlState);
>>>   GSThemeControlState buttonState =  (GSThemeControlState)[self 
>>> performSelector:aSelector withObject:nil];
>> 
>> This is not only wrong, it is undefined behaviour.  You are calling a 
>> function that returns an int (well, an enum, but in C that practically means 
>> an int) with a signature that returns a pointer.  You are then converting 
>> the 
>> result to an int.  If you are lucky, the calling convention will return an 
>> int and a pointer in the same place (register or stack), but this is not 
>> guaranteed by the language and, if the compiler spots that this is what 
>> you're doing then it is free to do whatever it likes with your code.
>> 
>> Concretely, it is almost certainly broken on 64-bit big-endian systems, 
>> where 
>> the int will be returned in the first 4 bytes of a register / stack location 
>> and this will be taking the second 4 bytes.  You may be lucky and find that 
>> the in-register return works, but it's fragile.
>> 
> 
> Thanks !  I feared it was too simple. So I still get the same problem : the 
> error in gcc does seem to come from the fact that [self  themeControlState] 
> returns an id (because private) when GSThemeControlState is an enum and not a 
> pointer.
> When I tried declare a category of NSButtonCell  to have this function 
> public, I thought I could use a selector to perform the call . But I still 
> get the same problem now : how will I have a return value that is for sure a 
> GSThemeControlState ?


Why would you use the selector if you already declared a category. Just having 
a category and using the method normally in the file should work.
As David already pointed out there is the remaining danger that this method 
might be removed from GNUstep and with the local category the compiler would 
not notice this.

Hope this helps,
Fred



reply via email to

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