[Top][All Lists]

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

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

From: David Chisnall
Subject: Re: Warning with clang, error with gcc : attached files
Date: Fri, 3 May 2019 13:01:43 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

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.

TL;DR: Please don't do this.


reply via email to

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