View Full Version : C function question
toddburch
Sep 15, 2007, 02:20 PM
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:
static VALUE
rb_obj_is_proc(proc)
VALUE proc;
{
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
kpua
Sep 15, 2007, 03:30 PM
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.
zimv20
Sep 15, 2007, 04:13 PM
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.
wittegijt
Sep 15, 2007, 04:49 PM
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.
toddburch
Sep 15, 2007, 05:12 PM
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
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.