473,779 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<dou ble> f);

void TestFn(int i, std::vector<dou ble> 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<dou ble> bf;
bf.resize(ndata - 1);

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

Jul 23 '05 #1
1 1821
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
1883
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 at mysql_real_query(). First time it executes the add_data() function successfully.
3
2560
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" lib_function(....); But when I run my C++ program, I get a segmentation fault in one of the library functions (not the function I directly called but one a few levels down in the calling hierarchy). According to the user manual provided with the...
22
2700
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 line #8 & line #14 Its only printing lines 10 & 11 & immediatly its giving seg fault. Please give suggestion to understand the internal things abt declaration/definition of pointer varibles. 1#include<stdio.h> 2
6
4780
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 fault. If I just call realloc( ) once before calling malloc( ), it is OK. Why? I am trying to read some double-typed items from infile and save them
5
6754
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() const { return _bdl.size(); }
5
1737
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 from outside it's definition which I am fairly sure I have seen done before. This code works: #define TEST(where,dimension,ptr) \ printf ("\tAll %s in %s values: ",where,dimension); \ pointer = mArray; \ while (pointer!=NULL) { \ printf...
10
6246
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 and should not be used),I don't know why.Any way,I decided to write my own gets()
6
2240
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* normaliseString(char *pstring) { char *ptr; for(ptr = pstring; *ptr; ptr++) {
10
12521
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. Now, that delete operation is giving me a segmentation fault. If I move the allocation and deletion of the pointer within the method where the pointer is being is used, it works okay ... but then another pointer gives a segmentation fault in...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.