# 1.9 Ruby C Extension?

**URL:** <https://www.ruby-forum.com/t/1-9-ruby-c-extension/145307>\
**Category:** Ruby\
**Created:** [August 7, 2008, 7:47pm UTC](https://www.ruby-forum.com/t/1-9-ruby-c-extension/145307 "2008-08-07T19:47:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![orlick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/53a042/32.png) [@orlick](https://www.ruby-forum.com/u/orlick)\
**Post date:** [August 7, 2008, 7:47pm UTC](https://www.ruby-forum.com/t/1-9-ruby-c-extension/145307/1 "2008-08-07T19:47:39Z")

</div>

Hi All,

When writing ruby extensions in C, how can I save C pointers into  
ruby  
variables Bignum or Fixnum?  
The only Macros available are INT2FIX, INT2NUM & FIX2INT and NUM2INT. I  
can  
not save a pinter value that is 32 bits long.

example:

static VALUE round\_trip(VALUE self, VALUE vptr)  
{  
void\* ptr = NUM2INT(vptr);  
return INT2NUM(ptr);  
}

---

<div class="post-metadata">

**Author:** ![orlick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/53a042/32.png) [@orlick](https://www.ruby-forum.com/u/orlick)\
**Post date:** [August 7, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/1-9-ruby-c-extension/145307/2 "2008-08-07T20:06:02Z")

</div>

Alex K. wrote:

> Hi All,
> 
> When writing ruby extensions in C, how can I save C pointers into  
> ruby  
> variables Bignum or Fixnum?  
> The only Macros available are INT2FIX, INT2NUM & FIX2INT and NUM2INT. I  
> can  
> not save a pinter value that is 32 bits long.
> 
> example:
> 
> static VALUE round\_trip(VALUE self, VALUE vptr)  
> {  
> void\* ptr = NUM2INT(vptr);  
> return INT2NUM(ptr);  
> }

I don’t think I’d do that. My inclination would be to create a structure  
to hold the pointer and wrap the structure into a Ruby object.

---

<div class="post-metadata">

**Author:** ![orlick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/53a042/32.png) [@orlick](https://www.ruby-forum.com/u/orlick)\
**Post date:** [August 7, 2008, 8:12pm UTC](https://www.ruby-forum.com/t/1-9-ruby-c-extension/145307/3 "2008-08-07T20:12:50Z")

</div>

On Thu, Aug 7, 2008 at 1:44 PM, Alex K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> {  
> void\* ptr = NUM2INT(vptr);  
> return INT2NUM(ptr);  
> }

Um, yeah, that, that’s just wrong. What exactly are you trying to  
accomplish with this extension?

In case you haven’t read it, please go read:  
[http://whytheluckystiff.net/ruby/pickaxe/](http://whytheluckystiff.net/ruby/pickaxe/), the chapter called  
Extending Ruby

Jason
