473,404 Members | 2,137 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,404 software developers and data experts.

what is this definition?

double ** matrix;
struct data_point
{
float x,y,z;
float nx,ny,nz;
float value;
};

Hi I have the following function definition. My question is what is
basic_func in that definition?
I have never seen this before. Can anyone tell me what it means?
matrix and data_point you can see them declared above, and inside the
function this is the only other place where basic_func is mentioned in
the code I am pasting from.

void makematrix_poly( double (*basic_func)(data_point *, data_point *) )
{
//....

matrix[pi+1][si+1] = (*basic_func)(&points[pi], &points[si]);

//....

}
Jul 22 '05 #1
3 1361
"Guybrush Threepwood" <sa***@sco.com> wrote in message
news:c2**********@newsg4.svr.pol.co.uk...
double ** matrix;
struct data_point
{
float x,y,z;
float nx,ny,nz;
float value;
};

Hi I have the following function definition. My question is what is
basic_func in that definition?
I have never seen this before. Can anyone tell me what it means?
matrix and data_point you can see them declared above, and inside the
function this is the only other place where basic_func is mentioned in
the code I am pasting from.

void makematrix_poly( double (*basic_func)(data_point *, data_point *) )
'basic_func' is a pointer to a function returing a double and taking two
'data_point' pointers as its arguments. To make it clearer, you usually use
a typedef and use the typdef'd name in the function:

typedef double (*pbasic_func)(data_point *, data_point *);
void makematrix_poly( pbasic_func basic_func )
{
//....

matrix[pi+1][si+1] = (*basic_func)(&points[pi], &points[si]);

//....

}


hth
--
jb

(replace y with x if you want to reply by e-mail)
Jul 22 '05 #2

hth
yes it does. Thank you
--
jb

(replace y with x if you want to reply by e-mail)

Jul 22 '05 #3
"Guybrush Threepwood" <sa***@sco.com> wrote in message
news:c2**********@newsg4.svr.pol.co.uk...
double ** matrix;
struct data_point
{
float x,y,z;
float nx,ny,nz;
float value;
};

Hi I have the following function definition. My question is what is
basic_func in that definition?
I have never seen this before. Can anyone tell me what it means?
matrix and data_point you can see them declared above, and inside the
function this is the only other place where basic_func is mentioned in
the code I am pasting from.

void makematrix_poly( double (*basic_func)(data_point *, data_point *) )
{
//....

matrix[pi+1][si+1] = (*basic_func)(&points[pi], &points[si]);

//....

}


double (*basic_func)(data_point *, data_point *)

Starting from the identifier (basic_func), the first operator in order of
precedence is * (dereference), so basic_func is a pointer (i.e., in an
expression, * dereferences the pointer to yield the object it points to).
The next operator is () (function call), so basic_func is a pointer to a
function. The rest of it is like any other function (parameters and return
type). So the complete type is: pointer to a function taking parameters
data_point *, data_point * and returning a double.

Note that the parentheses around *basic_func are necessary because the
function call parentheses have higher precedence than *. If they weren't
there you would have:
double *basic_func(data_point *, data_point *)

This time, the function call parentheses have the highest precedence, so
basic_func is a function. The * comes next, so it's a function returning a
pointer. The whole type is: function taking parameters data_point *,
data_point * and returning a double*.

(*basic_func)(&points[pi], &points[si]);

In the actual call, the pointer to function is dereferenced (*basic_func),
yielding the function itself. The rest is the same as an ordinary function
call.

DW

Jul 22 '05 #4

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

Similar topics

112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
31
by: Steven T. Hatton | last post by:
If a header is not necessarily a source file, and the sequences delimited by < and > in header names aren't necessarily valid source file names, what exactly is a header? -- p->m == (*p).m == p.m...
4
by: John | last post by:
Hi all; I write my first code using vector and list. When I run it, segmentation fault. Try to debug it, but it can not pass linking with -g option. What is the error with it? Thanks a lot....
5
by: Andy | last post by:
Hi, I got a little confused on 'instantiation' and 'specialization', espcially for explicit instantiation and explicit sepcialization. Can anybody explain the difference? Thanks a lot! ...
15
by: Greenhorn | last post by:
Hi, when a function doesn't specify a return type ,value what value is returned. In the below programme, the function sample()is returning the value passed to 'k'. sample(int); main() { int...
18
by: Seigfried | last post by:
I have to write a paper about object oriented programming and I'm doing some reading to make sure I understand it. In a book I'm reading, however, polymorphism is defined as: "the ability of two...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
11
by: satyspiceoflife | last post by:
int x,a; a=10 x=&a; cout<<*x; //using dereference operator this will print value 10 the other case is int *x; //x is a pointer variable int a=10; x=&a;
14
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Am I correct in thinking that the <signatureof a function is its <syntax> i.e. the arguments and the order in which they are specified when calling the function?
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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 projectplanning, coding, testing,...
0
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...

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.