From: John Joyce Date: 2007-03-25T09:16:08+09:00 Subject: Re: Ruby with C You mean C++ class? C doesn't have objects or classes. On Mar 25, 2007, at 8:54 AM, Harold Hausman wrote: > On 3/25/07, dogwasstar@hotmail.com wrote: >> Here is the C file >> >> static VALUE t_bit(VALUE self, VALUE obj) >> { >> VALUE n; >> >> n = NUM2INT(obj); >> printf("Fun %d", INT2NUM(n)); >> return Qnil; >> } >> >> > > Hi. > > By putting the variable 'n' through the INT2NUM macro as you pass it > into printf you're re-converting it back into a Ruby VALUE which is > not what you want to do. It will give you unpredictable (or at least > more-difficult-to-predict ;) ) results... > > Assuming you just want to print the value of 'obj' as an integer, you > should probably declare 'n' as an integer instead of as a VALUE, and > use the NUM2INT (as you have) to convert the Ruby VALUE 'obj' into a > plain int. Then you can pass it straight into printf (as you would > with any other int) ... no need for INT2NUM there. > > hope that helps, > -Harold >