Re: [Pyobjc-dev] caution with BOOL parameters
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-03-02 06:58:56
|
On Saturday, Mar 1, 2003, at 22:39 Europe/Amsterdam, bb...@ma... wrote: > On Saturday, Mar 1, 2003, at 15:18 US/Eastern, Ronald Oussoren wrote: >> On Saturday, Mar 1, 2003, at 20:56 Europe/Amsterdam, Bob Pasker wrote: >>> this begs the question: in pyobjc, is the 'c' in a method signature >>> ONLY used for BOOL types? >> Nope, 'c' is used for 'char', hence the _C_CHR ;-) ;-). > > What does _C_BFLD mean? I had used it successfully in the past for a > BOOL, but I don't remember why it worked or what it really means. Bitfield, is is used for bitfields in structs, e.g. struct foo { int bitfield:3; }. It might be possible to teach the bridge that an 8-bit bitfield is a BOOL, but I'm not sure if the objc-runtime would like that. > >> I'm afraid this is one of the places where the bridge cannot be >> completely transparent. In Python you can use any object as a boolean >> (most are evaluated as true, some are false), but with PyObjC you'll >> have to use small integers. > > I suppose that if the method really does want a (char) vs. a (BOOL), > then typecasting and losing the implied precision would be bad. > However, for (BOOL) methods, an (int) can be passed in pure ObjC.... You can also pass any integer type in Python, as long as its value is small enough. The following should give unexecpected results in Objective-C as well: - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender { return 1024; // True, isn't it? } Ronald |