Mixed Literals C90

In C99, if it xwas previously declared and has a type v2, I can write:

x = (v2) { 1, 2 };

where v2:

typedef struct {
    int x;
    int y;
} v2;

Is it possible to do something similar on the C90?

+3
source share
3 answers

AFAIK, complex characters were introduced precisely in the C99. However, if you use GCC, this feature is available as an extension. Citation GCC Documents :

ISO C99 supports complex literals. The combined literal looks like a listing containing an initializer. Its value is an object of the type specified in the listing containing the elements specified in the initializer; this value is lvalue. As an extension, GCC supports complex literals in C90 mode and in C ++ .

GCC:

GNU, GCC ( ISO C99, ). , , . . , .

static struct foo x = (struct foo) {1, 'a', 'b'};
static int y[] = (int []) {1, 2, 3};
static int z[] = (int [3]) {1};

:

static struct foo x = {1, 'a', 'b'};
static int y[] = {1, 2, 3};
static int z[] = {1, 0, 0};
+2

C90 :

{
    v2 temp = { 1, 2 };
    x = temp;
}

. ( C , , , .)

+2

No, this is a function of C99. However, some compilers will allow it to be used as an extension in C89 mode, for example. NKA.

+1
source

All Articles