[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Warning with clang, error with gcc : attached files
From: |
Bertrand Dekoninck |
Subject: |
Re: Warning with clang, error with gcc : attached files |
Date: |
Fri, 03 May 2019 14:42:55 +0200 |
User-agent: |
GNUMail (Version 1.3.0) |
On 2019-05-03 14:01:43 +0200 David Chisnall <gnustep@theravensnest.org> 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 ?
- Re: Warning with clang, error with gcc : attached files, David Chisnall, 2019/05/01
- Re: Warning with clang, error with gcc : attached files, Bertrand Dekoninck, 2019/05/03
- Re: Warning with clang, error with gcc : attached files, David Chisnall, 2019/05/03
- Re: Warning with clang, error with gcc : attached files,
Bertrand Dekoninck <=
- Re: Warning with clang, error with gcc : attached files, Fred Kiefer, 2019/05/03
- Re: Warning with clang, error with gcc : attached files, David Chisnall, 2019/05/03
- Re: Warning with clang, error with gcc : attached files, Bertrand Dekoninck, 2019/05/03
- Re: Warning with clang, error with gcc : attached files, Bertrand Dekoninck, 2019/05/03