Calloc problem

C

chingfulan

I have the following code and I can not figure out
why Stg2In returns a null pointer?
"Stg2In = (float *)calloc(9*DataLen, sizeof(float)); "
while
"Stg2Out = (float *)calloc(9*DataLen, sizeof(float));"
is sucessful?

Can anyone Help?

Thx


void IntepolatorFloat(float *DataOut,float *DataIn,int DataLen)

{

int i,j;
float *Stg1In;
float *Stg1Out;
float *Stg2In;
float *Stg2Out;
float *Stg3In;
float *Stg3Out;


//1st stage
Stg1In = (float *)calloc(3*DataLen, sizeof(float));
Stg1Out = (float *)calloc(3*DataLen, sizeof(float));
//Insert 0
for(i=0;i<DataLen;i++){
Stg1In[3*i]=DataIn;
Stg1In[3*i+1]=0;
Stg1In[3*i+2]=0;
}
//Filtering
for(i=28;i<3*DataLen;i++)
{
Stg1Out=0.0000;
for(j=0;j<sizeof(coeffFloat1)/4;j++){
Stg1Out=Stg1Out+coeffFloat1[j]*Stg1In[i-j];}

}

//End of First Stage

//Begin of stage 2


Stg2In = (float *)calloc(9*DataLen, sizeof(float));
Stg2Out = (float *)calloc(9*DataLen, sizeof(float));
//Insert 0
for(i=0;i<3*DataLen;i++){
Stg2In[3*i]=Stg1Out;
Stg2In[3*i+1]=0.0;
Stg2In[3*i+2]=0.0;
}
//Filtering
for(i=20;i<9*DataLen;i++)
{
for(j=0;j<sizeof(coeffFloat2)/4;j++){
Stg2Out=Stg2Out+coeffFloat2[j]*Stg2In[i-j];}

}


//end of Stage 2

//Begin of stage 3
Stg3In = (float *)calloc(18*DataLen, sizeof(float));
Stg3Out = (float *)calloc(18*DataLen, sizeof(float));
//Insert 0
for(i=0;i<9*DataLen;i++){
Stg3In[2*i]=Stg2Out;
Stg3In[2*i+1]=0;
}
//Filtering
for(i=10;i<18*DataLen;i++)
{

for(j=0;j<sizeof(coeffFloat3)/4;j++){
DataOut=DataOut+coeffFloat3[j]*Stg3In[i-j];}
DataOut=DataOut;
}


//end of Stage 3


free(Stg1In);
free(Stg1Out);
free(Stg2In);
free(Stg2Out);
free(Stg3In);
free(Stg3Out);


}
 
M

Mike Wahler

I have the following code and I can not figure out
why Stg2In returns a null pointer?
"Stg2In = (float *)calloc(9*DataLen, sizeof(float)); "
while
"Stg2Out = (float *)calloc(9*DataLen, sizeof(float));"
is sucessful?

Can anyone Help?

1. Did you #include <stdlib.h>?

2. Don't cast the return value from 'calloc()'

3. Have you checked the return value from *every*
call to 'calloc()'?

-Mike
 
R

Randy Howard

Mike Wahler wrote
(in article
1. Did you #include <stdlib.h>?

2. Don't cast the return value from 'calloc()'

3. Have you checked the return value from *every*
call to 'calloc()'?

4. Are you *sure* you want to use calloc() with floats?

5. why use float instead of double anyway?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top