C function question

Discussion in 'Mac Programming' started by toddburch, Sep 15, 2007.

  1. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #1
    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
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    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.
     
  3. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #3
    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.
     
  4. wittegijt macrumors member

    Joined:
    Feb 18, 2007
    Location:
    Eindhoven
    #4
    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.
     
  5. toddburch thread starter macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #5
    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
     

Share This Page