tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] { .field = value } struct initialization alternative


From: Ivan Medoedov
Subject: Re: [Tinycc-devel] { .field = value } struct initialization alternative
Date: Sun, 21 Jul 2019 19:56:59 +0200

Typo:

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


On Sun, Jul 21, 2019 at 7:56 PM Ivan Medoedov <address@hidden> 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 <address@hidden> 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
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]