On Tuesday, February 25, 2003, at 04:03 PM, Dan Mills wrote:

I only have one question: If I don't specify anything for my application_openFile function, it still seems to work perfectly. This makes sense for the arguments (it takes @@ and CB figures that out), but the return type is not void, which is the default.

Sorry, my bad - like the default args, the default return is actually '@', an object. That works when ObjC expects 'void', as well. Actually, any return type will work in that case, it will simply be ignored, because the caller won't know what to do with it.


What happens, then, when I return a value in that function? Does the caller in objc get it?

Interesting question!


The normal return type from the method you're declaring is a BOOL. When a scalar is given to ObjC in a context where it expects an object, the type of object that's created depends on the contents of the scalar. Perl converts scalars from strings to numbers automatically, but internally there are functions that one can use to get its current "native" type. So, if the scalar holds an int or a float value, an NSNumber object is created; if it holds a string, an NSString is created instead.

So, when you declare a method as returning an object (either by default or explicitly), and then do a "return 0;" at the end of that method, what is returned is an NSNumber object that holds a value of zero. The $65,535 question is - will the ObjC runtime call boolValue on this object to get the BOOL it needs?

I'll have to do some more digging to find out for certain. It would be pretty cool if it does, though - it would mean a lot more type-conversion magic going on behind the scenes than I'd anticipated, and a lot mere flexibility.

sherm--

Welcome to Rivendell, Mr. Anderson.

Reply via email to