# \[RubyCocoa\] C pointers, and documentation

**URL:** <https://www.ruby-forum.com/t/rubycocoa-c-pointers-and-documentation/155865>\
**Category:** Ruby\
**Created:** [December 17, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/rubycocoa-c-pointers-and-documentation/155865 "2008-12-17T19:21:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![polypus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5ac83/32.png) [@polypus](https://www.ruby-forum.com/u/polypus)\
**Post date:** [December 17, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/rubycocoa-c-pointers-and-documentation/155865/1 "2008-12-17T19:21:41Z")

</div>

hi,

how are C pointers handled on the rubycocoa side?  
for example a method like the following:

- (BOOL)validateValue:(id \*)ioValue  
forKey:(NSString \*)key  
error:(NSError \*\*)outError

is there a standard way of handling it? is this  
kind of thing documented anywhere?

thanks for any tips,  
\_c

---

<div class="post-metadata">

**Author:** ![polypus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b5ac83/32.png) [@polypus](https://www.ruby-forum.com/u/polypus)\
**Post date:** [December 18, 2008, 3:23pm UTC](https://www.ruby-forum.com/t/rubycocoa-c-pointers-and-documentation/155865/2 "2008-12-18T15:23:27Z")

</div>

On Dec 17, 2008, at 12:13 PM, Christophe M. wrote:

> ```
> error:(NSError **)outError
> 
> ```
> 
> is there a standard way of handling it? is this  
> kind of thing documented anywhere?

There’s a class called ObjcPtr that’s used to translate to/from such  
arguments. Google around for that word and you’ll find sketchy  
documentation. Here’s an example of stuffing a value into such an  
“out” parameter:

def getObjectValue\_forString\_errorDescription(objptr, s, errdesc)  
case s.to\_ruby.downcase  
when ‘yes’: objptr.assign(true)  
when ‘no’: objptr.assign(false)  
else return false  
end  
true  
end

To pull an object out of a pointer-to-object, you do this:

def observeValueForKeyPath\_ofObject\_change\_context(  
keyPath, object, change, rawContext)  
context = rawContext.cast\_as(‘@’)  
puts “Context: #{context.inspect}”  
end

The ‘@’ identifies the thing-being-pointed-to as an object. There are  
other symbols to identify things like raw machine integers, etc. I  
forget where you find them, but they’re not RubyCocoa-specific, so  
they’re somewhere in Apple documentation.

For non-objects there are also methods like “int\_at”, “bool\_at”,  
“bool”, and “int”. I haven’t had reason to use them yet, so I don’t  
know the details.

* * *

Brian M., independent consultant  
Mostly on agile methods with a testing slant  
[www.exampler.com](http://www.exampler.com), [Exploration Through Example](http://www.exampler.com/blog), [www.twitter.com/marick](http://www.twitter.com/marick)
