From: Tristin Davis on
[Note: parts of this message were removed to make it a legal post.]

I've been going over the Ruby API and I have a couple questions.

Why are the variables defined outside the block? What effect does this have
on the variables?

static VALUE
fsdbm_s_open(argc, argv, klass)
int argc;
VALUE *argv;
VALUE klass;
{
VALUE obj = Data_Wrap_Struct(klass, 0, free_sdbm, 0);

if (NIL_P(fsdbm_initialize(argc, argv, obj))) {
return Qnil;
}

if (rb_block_given_p()) {
return rb_ensure(rb_yield, obj, fsdbm_close, obj);
}

return obj;
}

I've always defined my variables inside a block.

static VALUE fsdbm_s_open(argc,argv,self) {
int argc;
VALUE *argv;
VALUE self
/* Etc */
}

From: Rolando Abarca on
On Jul 3, 2008, at 8:48 AM, Tristin Davis wrote:

> I've been going over the Ruby API and I have a couple questions.
>
> Why are the variables defined outside the block? What effect does
> this have
> on the variables?

they are not "outside" the block, it's just a way to define the type
of the variables in the function's signature. This:

> static VALUE
> fsdbm_s_open(argc, argv, klass)
> int argc;
> VALUE *argv;
> VALUE klass;
> {

is the same as this:

static VALUE
fsdbm_s_open(int argc, VALUE *argv, VALUE klass)
{

> I've always defined my variables inside a block.

now, I'm not sure you can do it that way...

> static VALUE fsdbm_s_open(argc,argv,self) {
> int argc;
> VALUE *argv;
> VALUE self
> /* Etc */
> }


regards,
--
Rolando Abarca M.





From: Tristin Davis on
[Note: parts of this message were removed to make it a legal post.]

So its just a style thing. That answers my question. Thank you.

On Thu, Jul 3, 2008 at 8:03 AM, Rolando Abarca <funkaster(a)gmail.com> wrote:

> On Jul 3, 2008, at 8:48 AM, Tristin Davis wrote:
>
> I've been going over the Ruby API and I have a couple questions.
>>
>> Why are the variables defined outside the block? What effect does this
>> have
>> on the variables?
>>
>
> they are not "outside" the block, it's just a way to define the type of the
> variables in the function's signature. This:
>
> static VALUE
>> fsdbm_s_open(argc, argv, klass)
>> int argc;
>> VALUE *argv;
>> VALUE klass;
>> {
>>
>
> is the same as this:
>
> static VALUE
> fsdbm_s_open(int argc, VALUE *argv, VALUE klass)
> {
>
> I've always defined my variables inside a block.
>>
>
> now, I'm not sure you can do it that way...
>
> static VALUE fsdbm_s_open(argc,argv,self) {
>> int argc;
>> VALUE *argv;
>> VALUE self
>> /* Etc */
>> }
>>
>
>
> regards,
> --
> Rolando Abarca M.
>
>
>
>
>
>

From: Rolando Abarca on
On Jul 3, 2008, at 9:12 AM, Tristin Davis wrote:

> So its just a style thing. That answers my question. Thank you.

btw, if you're even considering programming in C, you MUST have a copy
of K&R:

<http://www.amazon.com/Programming-Language-Prentice-Hall-Software/dp/0131103628/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1215091542&sr=8-1
>

(and of course, read it :-P)
regards,
--
Rolando Abarca M.





From: Ryan Davis on

On Jul 3, 2008, at 05:48 , Tristin Davis wrote:

> Why are the variables defined outside the block? What effect does
> this have
> on the variables?

Because ruby-core uses the ancient K&R style function definitions.
You're used to the almost-as-ancient ANSI style function definitions.
They're entirely equivalent, except the latter won't compile on
ancient C compilers. Stick to ANSI for clarity.