On 2019-05-03 14:01:43 +0200 David Chisnall <[email protected]> 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 ?


_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to