473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calloc problem

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[i];
Stg1In[3*i+1]=0;
Stg1In[3*i+2]=0;
}
//Filtering
for(i=28;i<3*DataLen;i++)
{
Stg1Out[i]=0.0000;
for(j=0;j<sizeof(coeffFloat1)/4;j++){
Stg1Out[i]=Stg1Out[i]+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[i];
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[i]=Stg2Out[i]+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[i];
Stg3In[2*i+1]=0;
}
//Filtering
for(i=10;i<18*DataLen;i++)
{

for(j=0;j<sizeof(coeffFloat3)/4;j++){
DataOut[i]=DataOut[i]+coeffFloat3[j]*Stg3In[i-j];}
DataOut[i]=DataOut[i];
}
//end of Stage 3
free(Stg1In);
free(Stg1Out);
free(Stg2In);
free(Stg2Out);
free(Stg3In);
free(Stg3Out);
}

Nov 15 '05 #1
2 1718

<ch********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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
Nov 15 '05 #2
Mike Wahler wrote
(in article
<cC***************@newsread3.news.pas.earthlink.ne t>):

<ch********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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()'?


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

5. why use float instead of double anyway?
--
Randy Howard (2reply remove FOOBAR)

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: dagger | last post by:
Hi there. I'm using C under FreeBSD with the gcc compiler and am having a bit of trouble using the calloc and realloc calls. As an example the code snippet: #include <stdio.h> int main() {...
16
by: laberth | last post by:
I've got a segmentation fault on a calloc and I don'tunderstand why? Here is what I use : typedef struct noeud { int val; struct noeud *fgauche; struct noeud *fdroit; } *arbre; //for those...
14
by: Rahul Gandhi | last post by:
Which one is more fast? malloc followed by memset or calloc
27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
40
by: boris | last post by:
Hi! I'm seeking some answers about what seems to be a memory leak. I have a loop that looks much like this: double *largeArray = (double*) calloc(); for (...) { printf("iteration #...\n");...
11
by: lohith.matad | last post by:
Hi all, Though the purpose of both malloc() and calloc() is the same, and as we also know that calloc() initializes the alloacted locations to 'zero', and also that malloc() is used for bytes...
7
by: mef526 | last post by:
I have had this problem for months now and it has been nagging me. I have a large project that has several C++ DLL's, one of them uses malloc / calloc / free for the other DLL's. I process very...
3
by: Alexander Behnke | last post by:
Hello, I am currently facing a problem with a calloc function call which returns a NULL pointer while in a debugging environment. If I start the same executable from the shell (not via the...
7
by: ds | last post by:
Hello all, I have a problem with calloc I have never seen before. I am migrating some C code to C++ and at some part in the C code there is a calloc that creates an array of structures. Now in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.