LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Initialized C pointer marked as uninitialized

Hello all,

why does the following code fails with "NON-FATAL RUN-TIME ERROR: Attempt to realloc uninitialized pointer" ? Even looking at the pointers with the debugger shows them as uninitialized instead of NULL... If I change "{0, Nb" to "{0, 0" it works !!!

 

#include <stdlib.h>

typedef struct sSpectro {
    int Max, Nb;
    double  *B, *I, *MaxVolt, *MQ;
} tSpectro;

static int Nb=50000;

int  main(void) {
    tSpectro Data={0, Nb, NULL, NULL, NULL, NULL};
//  Breakpoint on next line says that the pointers above are uninitialized. WHY?!?
//  Data.B=Data.I=Data.MaxVolt=Data.MQ=NULL;    // If I add this it works fine
    for (;;) {
        Data.I=realloc(Data.I, (Data.Nb=Nb)*sizeof(double));
        // Runtime error on the above line with:
        // NON-FATAL RUN-TIME ERROR:   Attempt to realloc uninitialized pointer.
        break;
    }
    free(Data.I);
}

 

0 Kudos
Message 1 of 4
(1,493 Views)

Hi

 

You are trying to initialize the structure with a variable(static int Nb)

 

Jan

 

0 Kudos
Message 2 of 4
(1,426 Views)

So ? That is valid C99, and even if not valid it should give a warning/error at compile time, not this weird 'uninitialized' runtime error.

0 Kudos
Message 3 of 4
(1,419 Views)

CVI at this point is not *fully* C99, but the initialization indeed should work as expected. Here is the... most recent (or less older!) info I could find in this respect: ANSI C99 Extensions in LabWindows/CVI 

 

I wonder whether using "designated" initializers would work:

 

typedef struct sSpectro {
    int Max, Nb;
    double  *B, *I, *MaxVolt, *MQ;
} tSpectro;

static int Nb=50000;

tSpectro Data={.Max=0, .Nb=Nb, .*B=NULL, .*I=NULL, .*MaxVolt=NULL, .*MQ=NULL};

 

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(1,403 Views)