Re: [Vala] Is it possible to do a reading buffer offset in vala?



JM píše v Út 09. 02. 2010 v 10:36 +0100:
Hi all 

I have a little problem on working with buffer offsets in vala.
In C doing an offset for a "char buf[SOME_SIZE];" is easy, but I have
difficulties doing it in vala.


You can simply use the same way you would in C. Cast your buffer to a
pointer and do pointer arithmetic with it.

Simple example:

void main ()
{
        char[] testbuffer = new char [8] { 0, 1, 2, 3, 4, 5, 6, 7 };
        char* testbufferoffset = ((char*)testbuffer) + 5;
        assert (testbufferoffset[0] == 5);
        testbufferoffset[1] = 25;
        assert (testbuffer[6] == 25);
}

Attachment: signature.asc
Description: Toto je digitálně podepsaná část zprávy



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