Re: [Vala] correct char ** binding



Hello,

                      في ث، 08-03-2011 عند 17:57 +0100 ، كتب Jan Spurny:
Hi Frederik,

'out string' will not work - that was the first thing I tried - problem is that if I would have used 'out 
string' in 'setup' function, the generated C code will pass some temporary variable to 'setup' and not the 
location of the required location. That is the reason why I've included that long explanation how it works. 
Maybe I was not clear enough, so let me explain again:

1) 'setup' functions takes 'location' of 'char*' destionation variable and stores it along with 'name' in 
'SomeParser' structure
2) 'run' then does the parsing and fills all locations described by their names by previous 'setup' calls
3) now all destionations registered with 'setup' are filled

I see two solutions here: either you use ref (even if it wasn't really
supposed to be used like this, it assumes the reference is valid), or
you use pointers. I feel pointers are the right thing to do here, but
you should take care with memory management. I'd use:

public void setup(string name, string** location);

and then you use it:

string a = null;
x.setup("variable_a", &a);

Using ref would probably work as well, but I prefer pointers as that
will make it clear to the user of the API that there is something
unusual here.


Another thing - I know that 'char *' is 'string', but why 'string a_str = a;' does not work?
You shouldn't know that ;-) Although they map to the same thing in C,
they are different things in Vala.

HTH,
Abderrahim




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]