Typo:

Foo* foo = ALLOC_INIT(Foo, { .field = 123, .field2 = 456 });


On Sun, Jul 21, 2019 at 7:56 PM Ivan Medoedov <ivan.medoe...@gmail.com>
wrote:

> Indeed. Sorry, my bad.
>
> Looks like the error is caused by __VA_ARGS__
>
> I'm using the following macro:
>
> #define ALLOC_INIT(type, ...) (type *)memdup((type[]){ __VA_ARGS__ },
> sizeof(type))
>
>
> https://tia.mat.br/posts/2015/05/01/initializing_a_heap_allocated_structure_in_c.html
>
> Foo* foo = ALLOC_INIT(Foo, { field: 123, field2: 456 });
>
> error: field expected
>
> This macro works fine with GCC and Clang.
>
>
> On Sun, Jul 21, 2019 at 6:50 PM Michael Matz <matz....@frakked.de> wrote:
>
>> Hi,
>>
>> On Sun, 21 Jul 2019, Ivan Medoedov wrote:
>>
>> > Hello,
>> > { .field = value } syntax is not supported by TCC.
>>
>> Why do you think so?
>>
>> % cat designated-init.c
>> struct S {
>>      int a, b;
>> };
>>
>> struct S s = {.a = 2, .b = 3};
>> % ./tcc -c designated-init.c && echo ok
>> ok
>> %
>>
>>
>> Ciao,
>> Michael.
>>
>> _______________________________________________
>> Tinycc-devel mailing list
>> Tinycc-devel@nongnu.org
>> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>>
>
_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to