Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

toddburch

macrumors 6502a
Original poster
Dec 4, 2006
748
0
Katy, Texas
I've been getting into C some more. I'm reviewing the source code for the Ruby language, and there are some constructs that I do not understand. I've reviewed my in-depth C book and have not come across this construct, and I even tried compiling a test program with this construct, and I got (as expected) compile errors. Here's an example construct:

Code:
static VALUE
rb_obj_is_proc(proc)
    [color=red]VALUE proc;[/color]
{
    if (TYPE(proc) == T_DATA && RDATA(proc)->dfree == (RUBY_DATA_FUNC)blk_free) {
	return Qtrue;
    }
    return Qfalse;
}

What's up with the declaration in red? (FYI, VALUE is defined as a unsigned long).

Thanks, Todd
 
I could be wrong, but I think it's just an alternate way of declaring the type of the parameters. You'll notice proc is not given a type in the parameter list between then parentheses. I think this is just a legacy feature of C. Why Ruby is using it is beyond me.
 
What's up with the declaration in red?

yeah, that's unexpected there. granted, i haven't programmed C in (errrr....) 15 years, so maybe the language has changed to include that.

perhaps the ruby guys wrote their own pre-processor to which such a construct makes sense.
 
I could be wrong, but I think it's just an alternate way of declaring the type of the parameters. You'll notice proc is not given a type in the parameter list between then parentheses. I think this is just a legacy feature of C. Why Ruby is using it is beyond me.

That is correct, it is pre-ANSI-C (K&R C). I thought ANSI-C compilers should not accept it, but I may be wrong.

Wittegijt.
 
Ah yes, K&R C, second edition, page 26. Old style, pre ANSI-C.

Thanks!!

Wow - that means in 1988, when the 2nd Ed. was published, this was "old" syntax.

Todd
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.