Re: [Vala] Trouble filling a char array in a struct



On Tue, Oct 18, 2011 at 10:45 PM, Jan-Jaap van der Geer
<jjvdgeer inbox com>wrote:

Pre Vala 0.13.2 I had code like this:

 var foo = Foo();
 Memory.copy(foo.Bar.Name, "foobar", 12);

This worked fine, as can be seen in the generated C:

 f foo = {0};
 memset (&foo, 0, sizeof (f));
 memcpy (foo.bar.name, "foobar", (gsize) 12);

(aren't the {0} and the memset() doing the same thing?)


Yes, ideally the memset could be avoided.
Try using a pointer, like Foo* foo = &bar; and then call memcpy on
foo->name.

-- 
www.debian.org - The Universal Operating System


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