This compiles without warnings using clang.
typedef struct {
int option;
int value;
} someType;
someType *init(someType *ptr) {
*ptr = (someType) {
.option = ptr->option | ANOTHEROPT,
.value = 1
};
return ptr;
}
int main()
{
someType *typePtr = init( &(someType) {
.option = SOMEOPT
});
// do something else with typePtr
}
Is this even valid C?
If so: What is the lifetime of the compound literal?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…