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

What is?

What is this exactly...

int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...
Please can some one help me out????

Jun 24 '07 #1
6 1689
Shraddha wrote:
What is this exactly...

int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...
Please can some one help me out????
ptr is a pointer to a function which accepts a single argument of type int.
This function returns a pointer to a function which accepts no arguments
and returns an int. It is more readable when written as

typedef int (*ptr_to_intfunc)(void);
ptr_to_intfunc (*ptr(int));
Jun 24 '07 #2
On Jun 24, 10:27 pm, Harald van D k <true...@gmail.comwrote:
Shraddha wrote:
What is this exactly...
int(*(*ptr (int))(void)
First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...
Please can some one help me out????

ptr is a pointer to a function which accepts a single argument of type int.
This function returns a pointer to a function which accepts no arguments
and returns an int. It is more readable when written as

typedef int (*ptr_to_intfunc)(void);
ptr_to_intfunc (*ptr(int));
No, first there is a typo. it should have a respective closing
parenthesis.

int(*(*ptr (int)))(void)

ptr is a function that takes int as an argument and returns a pointer
to a pointer to a function that takes no arguments are returns an
integer.

Jun 24 '07 #3
Shraddha wrote:
What is this exactly...

int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...
Your parentheses are not balanced:
There are three cases to rebalance them:

1) you mean: int(*(*xxx ) (int)) (void) ;
2) you mean: int(*(*yyy (int)) ) (void) ;
3) you mean: int(*(*zzz (int)) (void) );

=====
1) you mean: int(*(*xxx ) (int)) (void) ;
xxx is pointer to function taking parameter int and returning...
a pointer to function taking parameter void and returning int.

static int count= 0;
int dec_count(void) { return count--; }
int inc_count(void) { return count++; }
typedef int (* count_func) (void);
count_func selector(int k) { return k ? inc_count : dec_count; }

you can then make xxx point to function selector:
int(*(*xxx ) (int)) (void)= selector;
or...
count_func (*xxx) (int)= selector;

=====
2) you mean: int(*(*yyy (int)) ) (void) ;

this is the same as:
int (** yyy (int)) (void);

yyy is a function taking parameter int and returning...
pointer to pointer to function taking parameter void and returning int.

int two (void) { return 2; }
int one (void) { return 1; }
typedef int (* func) (void);
func one_bis= one, two_bis= two;

then yyy can be defined as:
int (** yyy (int k)) (void) { return k ? & two_bis : & one_bis; }
or in a more readable way:
func * yyy (int choice) { return k ? & two_bis : & one_bis; }

=====
3) you mean: int(*(*zzz (int)) (void) );
this is the same as
int* (*zzz (int)) (void);

zzz is a function taking parameter int and returning...
pointer to function taking parameter void and returning int*.

int* null (void) { return NULL; }
int* nonnull (void) { static int hell= 666; return & hell; }
typedef int* (* func) (void);

then zzz can be defined as:
int* (*zzz (int)) (void) { return k ? nonnull : null; }
or in a more readable way:
func zzz (int k) { return k ? nonnull : null; }

--
regis




Jun 24 '07 #4
regis wrote:
yyy can be defined as:
int (** yyy (int k)) (void) { return k ? & two_bis : & one_bis; }
or in a more readable way:
func * yyy (int choice) { return k ? & two_bis : & one_bis; }
Here, I meant:
func * yyy (int k) { return k ? & two_bis : & one_bis; }

zzz can be defined as:
int* (*zzz (int)) (void) { return k ? nonnull : null; }
or in a more readable way:
func zzz (int k) { return k ? nonnull : null; }
Here, I meant:
int* (*zzz (int k)) (void) { return k ? nonnull : null; }
Jun 24 '07 #5
Shraddha wrote:
int(*(*ptr (int))(void)

First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...
Check out a utility called "cdecl", but first (as suggested else-thread)
you will have to fix the syntax of this line.
--
clvrmnky <mailto:sp******@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
Jun 25 '07 #6
On Jun 25, 4:37 am, Clever Monkey <spamt...@clevermonkey.org.INVALID>
wrote:
Shraddha wrote:
int(*(*ptr (int))(void)
First I thought that this is the pointer to function...But I recognize
that the syntax iss quite different...
If we say that the function is taking void parameters i.e. no
parameters then what "(int i)" is doing there...

Check out a utility called "cdecl", but first (as suggested else-thread)
you will have to fix the syntax of this line.
--
clvrmnky <mailto:spamt...@clevermonkey.org>

Direct replies will be blacklisted. Replace "spamtrap" with my name to
contact me directly.
C:\cdecl>type test.txt
explain int(*(*xxx ) (int)) (void) ;
explain int(*(*yyy (int)) ) (void) ;
explain int(*(*zzz (int)) (void) );
C:\cdecl>cdecl < test.txt
declare xxx as pointer to function (int) returning pointer to function
(void) returning int
declare yyy as function (int) returning pointer to pointer to function
(void) returning int
declare zzz as function (int) returning pointer to function (void)
returning pointer to int

Jun 25 '07 #7

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

Similar topics

2
by: thecrow | last post by:
Alright, what the hell is going on here? In the following code, I expect the printed result to be: DEBUG: frank's last name is burns. Instead, what I get is: DEBUG: frank's last name is...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
12
by: Dario | last post by:
The following simple program behaves differently in Windows and Linux . #include <stdexcept> #include <iostream> #include <string> using namespace std; class LogicError : public logic_error {...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
8
by: Midnight Java Junkie | last post by:
Dear Colleagues: I feel that the dumbest questions are those that are never asked. I have been given the opportunity to get into .NET. Our organization has a subscription with Microsoft that...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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 project—planning, 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.