How does one return a C pointer reference from an Objective-C method?

Go To StackoverFlow.com

-1

If you have a C pointer which was defined in a method and are trying to return it from an object method in Objective C, what do you place as the return object type for the method?

For example, I am using code that converts a UIImage into an RGBA image map (as seen here) - but the code stores a C pointer to the memory that is unclear how to return.

- (??what goes here??) returnTextureRGB
{
  // ... other code ...
  void *imageData = malloc(height*width *r);
  // ... other code ...
  return(imageData);
}

What is the correct object type to declare being returned?

2012-04-05 01:10
by Praxiteles


1

I don't know why is this related to C#, however Objective-C is a superset of C, thus every C syntax is also a valid Objective-C syntax.

Just place void* as return type.

2012-04-05 01:14
by Manlio
Clarification: Objective-C. (C# was a typo - old habits and old jobs die hard.) Thanks - Praxiteles 2012-04-05 02:01


0

Well, you mention Objective-C, talk about C#... So it is not clear what exactly you are asking. For C#, you can use any type you want as long as its size is enough to store sizeof(void *) number of bytes (which is architecture-dependent, i.e. 64 bits on 86_64 architecture) and it has the same alignment (though alignment can be worked-around). For example, ulong will do. Objective-C transparently supports C, so just use a pointer data type as is.

2012-04-05 01:18
by NoName
Ads