A compound literal defined within a function has automatic lifetime associated with the block that contains it (i.e. the same lifetime as a variable declared on the same level). This is specified in the standard, paragraph 6.5.2.5p5.
int f() {
for (int i = 0; i < 10; ++i) {
int *j = (int []){i}; // storage duration of loop body
}
}
This essentially means that a compound literal is equivalent to a variable declared and initialized in the same scope:
int f() {
for (int i = 0; i < 10; ++i) {
int __unnamed[] = {i};
int *j = __unnamed;
}
}
Take care if passing compound literals anywhere their pointers could persist past their lifetime:
int f() {
int *p;
if (1) {
p = (int []){0, 1, 2};
assert(p[0] == 0);
}
// *p is undefined
}