Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > void *buffers, NSInvocation, and compiler encodings

void *buffers, NSInvocation, and compiler encodings
Thread Tools
GeeYouEye
Junior Member
Join Date: Mar 2003
Location: Walnut Creek, CA
Status: Offline
Reply With Quote
May 15, 2006, 05:57 PM
 
I'm working on a framework that uses NSInvocation, and I don't know what the return value is going to be from the invocation, or even what size it is ahead of time(could be anything, not just an object). To this end, I'm using -methodReturnSize and -methodReturnType to get the compiler encoding, and parsing that (and boy is that a PITA with structs and unions). No problem, I figure.

So I'm trying to follow the documentation:

First, find the size of the return value.
Second, parse the compiler encoding to make sure the result is going to be the right type. (this is relevant for other parts of the framework, especially since the return value won't always be an object). If it's an object or Class, pass the address of an id I've created for the return value to -getReturnValue:, and return it. Otherwise, continue.
Third, to actually get the return value, by creating a void *buffer of the size found in the first step, and passing it to -getReturnValue: (as per the documentation)
Here's the problem: I can't seem to get the value OUT of the buffer. I dereference it (say with [NSNumber numberWithFloat:*buffer]; ) and I get an error or warning about dereferencing a void *. I don't dereference it ([NSNumber numberWithFloat:buffer]) and I get an error for the non-integral types: "Incompatible type..." and a warning for the integral types: "conversion from pointer to integer without a cast".
Last (and once the above is working), wrap the return value in the appropriate object (either one from my framework, NSString, NSNumber, or NSData) and return that.

What am I doing wrong wrt: the buffer?
I bring order to chaos. You are in chaos windows, you are the contradiction, a bug wishing to be an OS.
     
GeeYouEye  (op)
Junior Member
Join Date: Mar 2003
Location: Walnut Creek, CA
Status: Offline
Reply With Quote
May 16, 2006, 04:14 AM
 
Found the problem... needed to cast the buffer to a pointer, and then dereference that.

Now to parse the compiler encodings for arrays, unions, and structs... ugh.
I bring order to chaos. You are in chaos windows, you are the contradiction, a bug wishing to be an OS.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:15 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,