[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[C ext to Ruby] variable args length and rb_class_new_instance

unbewust

8/21/2007 3:58:00 PM

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

4 Answers

Tim Hunter

8/21/2007 4:09:00 PM

0

unbewusst wrote:
> 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 ???

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


>
>
> 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 "&" ???

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 **".

>
> Yvon
>

Tim Pease

8/21/2007 4:10:00 PM

0

On 8/21/07, unbewusst <yvon.thoraval@gmail.com> wrote:
>
> 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 }
>

return rb_class_new_instance( 2, args, rb_path2class( "RFile" ) );

Blessings,
TwP

Nobuyoshi Nakada

8/21/2007 5:19:00 PM

0

Hi,

At Wed, 22 Aug 2007 01:29:57 +0900,
Tim Hunter 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 **.

--
Nobu Nakada

unbewust

8/22/2007 9:27:00 AM

0

On 21 ao?t, 19:19, Nobuyoshi Nakada <n...@ruby-lang.org> wrote:
> Hi,
>
> At Wed, 22 Aug 2007 01:29:57 +0900,
> Tim Hunter 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 **.
>
> --
> Nobu Nakada

ok thanks to all of you, i've found it bu myself

Yvon