# How to read a ruby symbol from C?

**URL:** <https://www.ruby-forum.com/t/how-to-read-a-ruby-symbol-from-c/112403>\
**Category:** Ruby\
**Created:** [August 18, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/how-to-read-a-ruby-symbol-from-c/112403 "2007-08-18T14:00:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unbewusst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ba9def/32.png) [@unbewusst](https://www.ruby-forum.com/u/unbewusst)\
**Post date:** [August 18, 2007, 2:00pm UTC](https://www.ruby-forum.com/t/how-to-read-a-ruby-symbol-from-c/112403/1 "2007-08-18T14:00:51Z")

</div>

I’m now able to produce a ruby symbol from C

I’m also able to read the keys of a hash, i need to know how to  
transform a key being a T\_SYMBOL into a cstring (the reverse) ???

also using :

long size = RHASH( ( VALUE )options\_hash )-\>tbl-\>num\_entries;

i get the following error at compil time :  
symbol\_test.c: In function m\_symbol\_test\_init:  
symbol\_test.c:109: error: dereferencing pointer to incomplete type

i don’t understand very much this message.  
however i can get the hash size by :

hlen = RARRAY( keys )-\>len;

with :

VALUE keys = rb\_funcall( options\_hash, rb\_intern( “keys” ), 0 );

my “options\_hash” is coming from :

rb\_scan\_args( argc, argv, “11”, &src\_path, &options\_hash );

it is a VALUE :

VALUE src\_path, options\_hash, noop, verbose;

help appreciated,

Yvon

---

<div class="post-metadata">

**Author:** ![unbewusst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ba9def/32.png) [@unbewusst](https://www.ruby-forum.com/u/unbewusst)\
**Post date:** [August 19, 2007, 5:28am UTC](https://www.ruby-forum.com/t/how-to-read-a-ruby-symbol-from-c/112403/2 "2007-08-19T05:28:32Z")

</div>

Hi,

At Sat, 18 Aug 2007 20:59:59 +0900,  
unbewusst wrote in [ruby-talk:265267]:

> i get the following error at compil time :  
> symbol\_test.c: In function m\_symbol\_test\_init:  
> symbol\_test.c:109: error: dereferencing pointer to incomplete type
> 
> i don’t understand very much this message.

You need to include st.h too.

But I guess what you need first is the knowledge of C.

---

<div class="post-metadata">

**Author:** ![unbewusst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ba9def/32.png) [@unbewusst](https://www.ruby-forum.com/u/unbewusst)\
**Post date:** [August 19, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/how-to-read-a-ruby-symbol-from-c/112403/3 "2007-08-19T18:45:44Z")

</div>

On 19 août, 05:27, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You need to include st.h too.
> 
> But I guess what you need first is the knowledge of C.

OK, thanks, including st.h is OK, BUT using :

rb\_id2name( SYM2ID( a key T\_SYMBOL from a RHASH ))

i get allways (null) even if i’m sure, from ruby side the, symbols  
are :

:verbose and :noop

isn’t the above the correct way to get the name of a symbol ???

Yvon

---

<div class="post-metadata">

**Author:** ![unbewusst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ba9def/32.png) [@unbewusst](https://www.ruby-forum.com/u/unbewusst)\
**Post date:** [August 20, 2007, 1:41am UTC](https://www.ruby-forum.com/t/how-to-read-a-ruby-symbol-from-c/112403/4 "2007-08-20T01:41:22Z")

</div>

Hi,

At Mon, 20 Aug 2007 01:44:57 +0900,  
unbewusst wrote in [ruby-talk:265404]:

> rb\_id2name( SYM2ID( a key T\_SYMBOL from a RHASH ))
> 
> i get allways (null) even if i’m sure, from ruby side the, symbols  
> are :
> 
> :verbose and :noop
> 
> isn’t the above the correct way to get the name of a symbol ???

That portion you mentioned is correct. So something is wrong  
where you didn’t.

---

<div class="post-metadata">

**Author:** ![unbewusst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/ba9def/32.png) [@unbewusst](https://www.ruby-forum.com/u/unbewusst)\
**Post date:** [August 20, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/how-to-read-a-ruby-symbol-from-c/112403/5 "2007-08-20T13:24:30Z")

</div>

On 20 août, 01:40, Nobuyoshi N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > :verbose and :noop
> 
> > isn’t the above the correct way to get the name of a symbol ???
> 
> That portion you mentioned is correct. So something is wrong  
> where you didn’t.

OK, i’ll look again at that…

thanks,

Yvon
