From: "LESS Software, Inc" Date: 2001-12-06T17:55:11+09:00 Subject: [ruby-talk:27660] Re: Class variables in C Hi matz, here the code fragment: void Init_cups() { VALUE cCups; cCups = rb_define_class("CUPS", rb_cObject); /* constructor */ rb_define_method(cCups, "initialize", cups_init, 0); /* class structs */ S_Printer = rb_struct_define("Printer", "name", "instance", "options", 0); /* class-variables */ rb_define_class_variable(cCups, "@@init", Qfalse); rb_define_class_variable(cCups, "@@printers", Qnil); rb_define_class_variable(cCups, "@@classes", Qnil); . . static VALUE cups_init(VALUE self) { int num_descs, i, j; VALUE opthash, st, printers, classes, pr, ok, ov, init; cups_dest_t *dests; cups_option_t *opts; /* instance variables */ rb_iv_set(self, "@copies", INT2FIX(1)); rb_iv_set(self, "@filedesc", INT2FIX(Qnil)); rb_iv_set(self, "@tempfile", INT2FIX(Qnil)); rb_iv_set(self, "@printer", INT2FIX(Qnil)); rb_iv_set(self, "@title", INT2FIX(Qnil)); rb_iv_set(self, "@pageno", INT2FIX(0)); /* initialize class variables only once */ if (rb_cv_get(self, "@@init") == Qfalse) { rb_cv_set(self, "@@init", Qtrue); . . . In my 'sample.rb' (ruby 1.6.5) the statement prt = CUPS.new give me the error message: ./sample.rb:5:'in initialize': uninitialized class variable @@init in # (NameError) Thanks. Harald -----Urspr�ngliche Nachricht----- Von: Yukihiro Matsumoto An: ruby-talk ML Datum: Donnerstag, 6. Dezember 2001 06:32 Betreff: [ruby-talk:27629] Re: Class variables in C >Hi, > >In message "[ruby-talk:27571] Class variables in C" > on 01/12/06, "LESS Software, Inc" writes: > >|I've declared a class variable with rb_declare_class_variable(class, name, value) in C. Using this I've got >|the errror: uninitialized class variable. May anyone help me? > >More information required. Could you give me exact code and error >messages? > > matz. >