View Single Post
Old 18 December 2019, 10:08   #1
deimos
Registered User

 
Join Date: Jul 2018
Location: France
Posts: 545
Is this legal C?

Is this correct / legal C99, and will it do what I expect?

Code:
void AFunction(void) {
    WORD * kludge = NULL;

    // ...

    if (topLeft) {
        kludge = (WORD []) { 0, 1 };
    }

    // ....

    DoSomethingWith(kludge);
}
i.e. is the WORD [] containing the values 0 and 1 available outside of the scope of the if statement that it is declared in? Is it really allocated in the stack frame for the function, or does it end disappearing when the if statement completes, leaving kludge pointing to potential garbage?
deimos is offline  
 
Page generated in 0.04151 seconds with 11 queries