# Variable args length and rb\_class\_new\_instance

**URL:** <https://www.ruby-forum.com/t/variable-args-length-and-rb-class-new-instance/112638>\
**Category:** Ruby\
**Created:** [August 21, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/variable-args-length-and-rb-class-new-instance/112638 "2007-08-21T18:01:08Z")\
**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 21, 2007, 6:01pm UTC](https://www.ruby-forum.com/t/variable-args-length-and-rb-class-new-instance/112638/1 "2007-08-21T18:01:08Z")

</div>

i did a first try calling rb\_class\_new\_instance with variable args  
length :

rosxutils.c: In function m\_rfile\_wo:  
rosxutils.c:1870: error: parse error before [ token

1867 VALUE m\_rfile\_wo ( VALUE self, VALUE file, VALUE options )  
1868 {  
1869 char \*cfile = StringValuePtr ( file );  
1870 VALUE[2] args;  
1871 //VALUE args[2];  
1872 args[0] = file;  
1873 args[1] = options;  
1874 return rb\_class\_new\_instance ( 2, &args, rb\_path2class  
( “RFile” ) );  
1875 }

HERE i don’t see where is the parse error ???

rosxutils.c: In function m\_rfile\_wo:  
rosxutils.c:1874: warning: passing argument 2 of rb\_class\_new\_instance  
from incompatible pointer type

1867 VALUE m\_rfile\_wo ( VALUE self, VALUE file, VALUE options )  
1868 {  
1869 char \*cfile = StringValuePtr ( file );  
1870 //VALUE [2] args;  
1871 VALUE args[2];  
1872 args[0] = file;  
1873 args[1] = options;  
1874 return rb\_class\_new\_instance ( 2, &args, rb\_path2class  
( “RFile” ) );  
1875 }

AND HERE why the pointer is incompatible, because of the “&” ???

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 21, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/variable-args-length-and-rb-class-new-instance/112638/2 "2007-08-21T18:11:11Z")

</div>

On 8/21/07, unbewusst [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 1875 }

return rb\_class\_new\_instance( 2, args, rb\_path2class( “RFile” ) );

Blessings,  
TwP

---

<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 21, 2007, 6:32pm UTC](https://www.ruby-forum.com/t/variable-args-length-and-rb-class-new-instance/112638/3 "2007-08-21T18:32:14Z")

</div>

unbewusst wrote:

> 1871 //VALUE args[2];  
> 1872 args[0] = file;  
> 1873 args[1] = options;  
> 1874 return rb\_class\_new\_instance ( 2, &args, rb\_path2class  
> ( “RFile” ) );  
> 1875 }
> 
> HERE i don’t see where is the parse error ???

“VALUE[2] args;” is not valid C.  
You need to use VALUE args[2];

> 1871 VALUE args[2];  
> 1872 args[0] = file;  
> 1873 args[1] = options;  
> 1874 return rb\_class\_new\_instance ( 2, &args, rb\_path2class  
> ( “RFile” ) );  
> 1875 }
> 
> AND HERE why the pointer is incompatible, because of the “&” ???

Yes. In this context, “args” is a pointer to a VALUE, or “VALUE \*”.  
&args is then a pointer to a pointer to a VALUE, or “VALUE \*\*”.

---

<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 22, 2007, 11:31am UTC](https://www.ruby-forum.com/t/variable-args-length-and-rb-class-new-instance/112638/4 "2007-08-22T11:31:27Z")

</div>

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

> Nobu Nakada  
> ok thanks to all of you, i’ve found it bu myself

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 21, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/variable-args-length-and-rb-class-new-instance/112638/5 "2007-08-21T19:20:22Z")

</div>

Hi,

At Wed, 22 Aug 2007 01:29:57 +0900,  
Tim H. wrote in [ruby-talk:265676]:

> &args is then a pointer to a pointer to a VALUE, or “VALUE \*\*”.

VALUE (\*)[2] which is different from VALUE \*\*.
