Conversation

A question for the compiler nerds: if I have a (C) function that uses a lot of intermediate local structs or fixed size arrays that are not long-lived inside that function, can I trust the C compiler to re-use the memory?
1
E.g. void compute(int init) { int a[100]; f(a,100,init); // compute a[] from init int b[100]; g(a,b,100); // compute b[] from a[] // a is no longer referenced after this, so c can use a's storage int c[100]; g(b,c,100); // compute c[] from b[] }
1
Basically I want to be lazy and leave this to the lower level compiler (C compiler, or LLVM), and I do not want to generate my own local buffer management code. So essentially, my generated code is SSA at the buffer level, where low level compiler would figure out buffer re-use.
1
I understand that this is not easy to optimize for structures that are not the same size, but in my use case they would be. Mostly just fixed size arrays.
1