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

[Function pointer] Translating these typedefs into one

typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.

Oct 12 '06 #1
5 1564
ma*******@googlemail.com wrote:
typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.
No you got the return type wrong. You need to substitute
the rest of the function declaration where int_arg goes in
the original typedef:
typedef void (*(*ultra)(int*, int*, int_arg))(int);
Oct 12 '06 #2
ma*******@googlemail.com wrote:
typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.
Try this:

typedef void (*ultra(int*, int*, void(*)(int)))(int);

Krishanu
Oct 12 '06 #3

(1) typedef void (*int_arg)(int);

This is a pointer to a function which takes an int and returns void.
(2) typedef int_arg (*pf)(int*,int*,int_arg);

This is a pointer to a function which takes three arguments:

[i] int*
[ii] int*
[iii] void (*)(int)

And whose return type is:

void (*)(int);

Here's how we put them together. First of all, start off with the function
return type, which is ultimately the "fundamental type" of the entire
declaration:

void (*pf)(int);

From here, we turn it into a function by putting parentheses directly after
the name, and filling these parentheses with the function parameter types:

void ( *pf(int*,int*,void(*)(int)) )(int)

We now turn this into a pointer to what it already is by enclosing the name
in parentheses with an asterisk:

typedef void ( *(*pf)(int*,int*,void(*)(int)) )(int);

As follows:

typedef void (*int_arg)(int);

/* typedef int_arg (*pf)(int*,int*,int_arg); */

typedef void ( *(*pf)(int*,int*,void(*)(int)) )(int);

int main()
{
int_arg x;

pf p;

x = p(0,0,x);
}

--

Frederick Gotham
Oct 12 '06 #4
Krishanu Debnath wrote:
ma*******@googlemail.com wrote:
>typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.

Try this:

typedef void (*ultra(int*, int*, void(*)(int)))(int);

Krishanu
He could try it, but it wouldn't be right
*ultra( ... ) is a function returning pointer
not pointer to function. You need one more set of parens.
Oct 12 '06 #5
Ron Natalie wrote:
Krishanu Debnath wrote:
>ma*******@googlemail.com wrote:
>>typedef void(*int_arg)(int);
typedef int_arg(*pf)(int*,int*,int_arg);

I tried this:

typedef void(*)(int)(*ultra)(int*,int*,void(*)(int));

and got a syntax error.

Try this:

typedef void (*ultra(int*, int*, void(*)(int)))(int);

Krishanu
He could try it, but it wouldn't be right
*ultra( ... ) is a function returning pointer
not pointer to function. You need one more set of parens.
You are right of course. Thanks for the correction.

Krishanu
Oct 12 '06 #6

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

Similar topics

3
by: Jan-Henrik Grobe | last post by:
Hallo, I am coming to this newsgroup with a very strange Problem. I have two c++ files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in B.cpp I have stored the callback...
9
by: Andy Lomax | last post by:
gcc 3.3 allowed a typedef for a function pointer to contain default argument specifications; for example: typedef int (*foo) (int, int, int=0, bar=0); However, it turns out that this is...
26
by: Adam Warner | last post by:
Hello all, I'm very new to C but I have a number of years of Common Lisp programming experience. I'm trying to figure out ways of translating higher order concepts such as closures into C. The...
15
by: Daniel Rudy | last post by:
Hello, Consider the following code: /* resolve_hostname this resolves the hostname into an ip address. */ static void resolve_hostname(char result, const char hostname, const char server) {
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
17
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ...
7
by: juerg.lemke | last post by:
Hi everyone I am interested in having multiple functions with different prototypes and deciding, by setting a pointer, which of them to use later in the program. Eg: int f1(void); char*...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
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
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: 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: 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...
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
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.