473,385 Members | 1,867 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.

calling a function (passed as a pointer) causing segmentation fault

I get a segmentation fault in my program when calling a function
"TestFn" that has been passed as a pointer into another function.
The following excerpt should give enough information as to what I am
doing wrong...

typedef void TIdxMultiFunc (int i, std::vector<double> f);

void TestFn(int i, std::vector<double> f)
{
double t; // execution does not get this far
...
f[0] = t*t;
f[1] = t*t*t;
}

void TestSolve(std::vector<double> &a)
{
....
TIdxMultiFunc *ptr = &TestFn;
afn(y, ptr, 2);
}

void afn(std::vector<double> &y, TIdxMultiFunc *f, int n)
{
....
int i;
std::vector<double> bf;
bf.resize(ndata - 1);

for (i = 0; i < n; i++)
{
f(i, bf); // segmentation fault occurs here

Jul 23 '05 #1
1 1792
PS. ndata should read n

Jul 23 '05 #2

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

Similar topics

1
by: Manpreet | last post by:
Hi all, I am using mysql C API in my C++ project. I am using mysql-4.1.4-gamma and gcc 3.2.2. Problem with this code is that when add_data(i) is called second time SEGMENTATION FAULT occurs...
3
by: Glenn C. Rhoads | last post by:
I'm having a problem calling a C function from a publicly available library file. To get the code to compile, I had to declare the function as an external C function as follows. extern "C"...
22
by: bvb | last post by:
Hi, while declaring/defining pointer to int/char, What is doing the compiler exactly . i'm able to get output(String) for all pointer to char definition(without line # 8&14). But when i include...
6
by: I_have_nothing | last post by:
Hi! I am new in C. I try to use dynamical allocation fuction malloc( ) and realloc( ). I found something strange. After several calling realloc( ), the malloc( ) will give me a Segmentation...
5
by: silverburgh.meryl | last post by:
Hi, I have a segmentation fault in line 66 of GroupResult.h and I can't figure out why that causes any problem, I appreciate if anyone can help. line 66 of Result.h: 66 size_t size()...
5
by: Ben | last post by:
This is a follow-on from the "Help with array/pointer segmentation fault needed" thread.. I have not been able to find much information on the rules for macros. I want to be able to call a macro...
10
by: paytam | last post by:
hi all can you tell me what's the wrong with this code? I use gcc compiler,but when I wanted to use gets() function in my code but it takes a dangerous warning(the gets function is dangerous...
6
by: tgnelson85 | last post by:
Hello, I've managed to get my c++ code calling my c code, and i can call a function that prints something to the screen etc. However, i am trying to call the following C function: char*...
10
by: H.S. | last post by:
Hello, I have class in which I am allocating space for a double array in the constructor. I use the double array twice in one of the methods and then delete that array in the class's destructor....
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.