473,383 Members | 1,821 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,383 software developers and data experts.

struggling with void pointers/functions/structures

Hello,

I am trying to run a code which compiles fine, but when I try to run it
I am facing a series of problems which are quite difficult to
understand. I am kind of new with C, the task is then a little
challenging.

First, the routine where it crashes starts like this

void read_instructions(E,argc,argv)
struct All_variables *E;

........E is then used in a series of functions and points to different
structures without causing any trouble

(E->problem_initial_fields)(E);
........the code seems to crash here

problem_initial_fields is defined in a header file that is included in
the routine

struct All_variables {
#include "convection_variables.h"
.....
void (* problem_initial_fields)();
.....
},

Can anybody explain to me what it actually means and have some
suggestions on the reasons for crashing. Is there a way I could print
out some of the values it seems to point to?

Thank you,
F.

Feb 17 '06 #1
1 1245
"cirederf" <fr******@gps.caltech.edu> writes:
I am trying to run a code which compiles fine, but when I try to run it
I am facing a series of problems which are quite difficult to
understand. I am kind of new with C, the task is then a little
challenging.

First, the routine where it crashes starts like this

void read_instructions(E,argc,argv)
struct All_variables *E;

.......E is then used in a series of functions and points to different
structures without causing any trouble

(E->problem_initial_fields)(E);
.......the code seems to crash here

problem_initial_fields is defined in a header file that is included in
the routine

struct All_variables {
#include "convection_variables.h"
....
void (* problem_initial_fields)();
....
},

Can anybody explain to me what it actually means and have some
suggestions on the reasons for crashing. Is there a way I could print
out some of the values it seems to point to?


You have an old-style (non-prototype) declaration for your
read_instructions routine. This isn't wrong, but there's no reason to
do this. Rather than

void read_instructions(E, argc, argv)
struct All_variables *E;
int argc;
char **argv
{
...
}

you should use the more modern (i.e., since 1989):

void read_instructions(struct All_variables *E, int argc, char **argv)
{
...
}

This allows the compiler to do more checking.

Based on what little code you've shown us, the problem_initial_fields
member is a function pointer. You don't show us any code that assigns
a value to that pointer (nor do you show us the call to
read_instructions()). If it doesn't have a proper value, any attempt
to call through it will invoke undefined behavior, most likely a
crash.

There's no standard way to print the value of a function pointer, but
something like this:

printf("E->problem_initial_fields = %p\n",
(void*)E->problem_initial_fields);

may tell you something. The output will most likely look like a
hexadecimal number; if nothing else a null pointer should be
recognizable.

If you're still having trouble, see if you can create a small,
self-contained, compilable program that exhibits the problem.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 17 '06 #2

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

Similar topics

52
by: Vladimir Grul | last post by:
Hello, I have a class member function declared as class some_class { .... virtual int call(void); }; Can I use this-> inside the function body?
15
by: Stig Brautaset | last post by:
Hi group, I'm playing with a little generic linked list/stack library, and have a little problem with the interface of the pop() function. If I used a struct like this it would be simple: ...
52
by: Douglas Garstang | last post by:
I can't believe I've been trying to work this out for hours now, and I can't believe I couldn't find someone asking for a similar solution in the newsgroups. No wonder I hate C so much, and every...
8
by: John Hanley | last post by:
I working in C. I haven't paid much attention to void pointers in the past, but I am wondering if I can use them for my various linked lists to save work. I have two different linked lists that...
6
by: MackS | last post by:
Hi FAQ 4.9 states that void** cannot be used portably "to pass a generic pointer to a function by reference". I would like to hear from you whether there is anything wrong with the following...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
10
by: arnuld | last post by:
thanks
10
by: kkirtac | last post by:
Hi, i have a void pointer and i cast it to an appropriate known type before using. The types which i cast this void* to are, from the Intel's open source computer vision library. Here is my piece...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.