Re: [Vala] Void*, how to deal with it



On Mi, 2010-06-30 at 14:26 +0100, Harry Van Haaren wrote:
Hey All,

I've got a function in the JACK.vapi binding, that returns a buffer. Now it
doesnt "physically"
return the buffer, but returns a  void*  to the buffer.

I checked the Vala tutorial for any references to void*, and didnt find
anything...

This is the function (to be called on a Port object):
public void* get_buffer(NFrames nframes);         // nframes is a uint32..
not that it matters

And this is what I tried (master_l is of Port type):
var buffer = master_l.get_buffer(nframes);

And what I want to do with this buffer is the following:
    for(int i = 0; i < (uint32) nframes; i++)
    {
        buffer[i] = array[i];   // have an array of samples, need to write
them to this void* buffer.
    }

You shouldn't expect something like this to work, as you basically
dereference a void* (buffer[i] would be void, but void has no size, so
that won't work). You must always cast it to a pointer of a type with a
size, such as char.

-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.





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