Strange "selector manipulation" in Objective-C method with boolean arguments
I need to dynamically regenerate method names using runtime reflection calls. But get weird results for some.
My TestClass contains a method like:
- (void)testMethod6_NSRect:(NSRect)a1 int:(int)a2 int:(int)a3 bool:(Boolean)a4 {
...
}
When listing the above classes using the class_copyMethodList () method and method selectors using the method_getName () method, I get:
"testMethod6_NSRect:int:int:_Bool:"
So the selector was somehow rewritten (with gcc?) To make "_Bool" with "bool". As far as I've tested yet, this seems to only work for the "bool" selector part - if I change it to int: (int), as in:
- (void)testMethod1_int:(int)a1 int:(int)a2 int:(int)a3 int:(int)a4 {
...
}
I get the expected:
"testMethod1_int:int:int:int:"
Q: Does anyone know the rules or a pointer to where I could find them for this "selector rewrite", or am I missing something? Is this for "bool" only? I also need to know if this behavior depends on gcc version, osx version or runtime version.
I am using (gcc -version): i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (point 3) on (uname -a) 10.8.0 Darwin Kernel Version 10.8. 0:
source to share
The problem lies in the ugly piece of preprocessor magic in the standard C99 header <stdbool.h>
:
#define bool _Bool
C99 defines a named type _Bool
that behaves like a C ++ type bool
. The determinant should be able to use it in C, but with a C ++ identifier.
Decision:
#undef bool
source to share