473,382 Members | 1,786 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.

pointer definitions

Hello all,

typedef int (*foo) ();

typedef foo (*bar) ();

How to define bar with a single typedef?

I still have not understood the parsing...

Jens
Sep 8 '06 #1
5 1647

Jens Theisen wrote:
Hello all,

typedef int (*foo) ();

typedef foo (*bar) ();

How to define bar with a single typedef?
hehehe

typedef int (*(*bar)())();

cute, no?

Sep 8 '06 #2
Jens Theisen wrote:
Hello all,

typedef int (*foo) ();

typedef foo (*bar) ();

How to define bar with a single typedef?
Why would you want to? The typedefs (if they were appropriately named)
make life a lot easier.

Bar being a pointer to a function with no parameters that returns a
[pointer to a function with no params that returns int]

But if you really want it, try:

typedef int (*(*bar)())();

Personally, I find the one with two typedefs much easier to read and
understand.

Sep 8 '06 #3
Noah Roberts wrote:
hehehe

typedef int (*(*bar)())();
To read that, walk up the precedents to the highest precendent item, bar,
and then say the name of each term in order of descending precedence, going
out.

bar is a pointer to a function that returns a pointer to a function that
returns int.
cute, no?
Now don't do it, and use typedefs early and often in production code!

Question for Jens: Can you write a pointer to a function that returns a
pointer to a function with the same signature and return value? ;-)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Sep 8 '06 #4
Jens Theisen wrote:
typedef int (*foo) ();

typedef foo (*bar) ();

How to define bar with a single typedef?
Is this homework?

'foo' is a pointer to a function that takes no args and returns
an int. 'bar' is a pointer to a function that takes no args and
returns a pointer to a function that takes no args and returns
an int. I think it should be

typedef int (*((*bar)()))();

How to verify it? I'll leave it to you.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 8 '06 #5
"Phlip" <ph******@yahoo.comwrites:
Noah Roberts wrote:
typedef int (*(*bar)())();
Ah ja, now I recall..
Now don't do it, and use typedefs early and often in production code!
Oooh...
Question for Jens: Can you write a pointer to a function that returns a
pointer to a function with the same signature and return value? ;-)
struct rec : boost::function< rec () { };

If you were talking about C-pointers to functions rather than
functors, I give up!

Jens
Sep 8 '06 #6

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

Similar topics

6
by: Bob Keith | last post by:
I am a beginner. So this question could be very stupid. I am not very clear about the pointer in C++, would anyone let me know the difference of the following usage of pointer. int* a int *a...
15
by: Mon | last post by:
I am in the process of reorganizing my code and came across and I came across a problem, as described in the subject line of this posting. I have many classes that have instances of other classes...
31
by: vp | last post by:
If I have a pointer char * p, is it correct to assign NULL to this pointer by: "memset( &p, 0, sizeof(p));" instead of "p = NULL;" The reason I ask is I have an array of structure of N...
7
by: Marcus Jacobs | last post by:
Before I am flamed, I did search the FAQ for an answer to the question that I am about to post. Even with a search of the newsgroup archive, there are so many subjects about pointers I could search...
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 .
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
5
by: caleb.vandyke | last post by:
I am working with some code that is doing some pointer to structure casts and I can't figure out how the cast is being done. Here is basically the code. #include <stdio.h> #include <stdlib.h> ...
20
by: svata | last post by:
Hello there, after some time of pondering I come to some solution which would suit me best. Please correct, if I am wrong. Function has two parameters. A string array, better said a pointer to...
10
by: Ahmad Humayun | last post by:
Whats the difference between: char str1 = "wxyz"; char* str2 = "abcd"; I can do this: str2 = str1 but I can't do this: str1 = str2
49
by: Davy | last post by:
Hi all, I am writing a function, which return the pointer of the int. But it seems to be wrong. Any suggestion? int * get_p_t(int t) { return &t; } int main()
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
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: 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...
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
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.