From: "Brett H. Williams" Date: 2003-07-25T05:54:39+09:00 Subject: Re: SWIG and char * parameters On Jul 25, Ben Giddings wrote: > I've just started to try to use SWIG to wrap a bunch of C functions so I can > call them from Ruby. If I can get this working it will make some testing > much easier, but I've come across a strange problem. Functions which take > char pointer arguments seem to pass in NULL. > > ##### > > void sayHelloTo(char *name) { > if (NULL == name) { > printf("Hello %s\n", name); > } > else { > printf("Gimme a name!\n"); > } > } > > ##### > > ben% irb > irb(main):001:0> require 'sample' > => true > irb(main):002:0> Sample.sayHello > Hello World > => nil > irb(main):003:0> Sample.sayHelloTo > ArgumentError: wrong # of arguments(0 for 1) > from (irb):3:in `sayHelloTo' > from (irb):3 > irb(main):004:0> Sample.sayHelloTo("Bob") > Gimme a name! > => nil > > I've looked over the documentation on the generic and Ruby-specific parts of > the SWIG site and haven't found anything talking about this issue. Any tips, > pointers, URLs or comments? Looks like it does exactly what you told it to. You passed in Bob. Therefore, NULL != name, and so it says "Gimme a name!". Try passing in nil, you'll get a seg fault :) What you want is NULL != name. Not SWIG, just C. HTH, -- ---------------------------------------------- | -------------------------- Brett Williams | ---------------------------------------------- | --------------------------