Connecting Tech Pros Worldwide Forums | Help | Site Map

pointer definitions

Jens Theisen
Guest
 
Posts: n/a
#1: Sep 8 '06
Hello all,

typedef int (*foo) ();

typedef foo (*bar) ();

How to define bar with a single typedef?

I still have not understood the parsing...

Jens
Noah Roberts
Guest
 
Posts: n/a
#2: Sep 8 '06

re: pointer definitions



Jens Theisen wrote:
Quote:
Hello all,
>
typedef int (*foo) ();
>
typedef foo (*bar) ();
>
How to define bar with a single typedef?
hehehe

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

cute, no?

red floyd
Guest
 
Posts: n/a
#3: Sep 8 '06

re: pointer definitions


Jens Theisen wrote:
Quote:
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.

Phlip
Guest
 
Posts: n/a
#4: Sep 8 '06

re: pointer definitions


Noah Roberts wrote:
Quote:
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.
Quote:
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!!!


Victor Bazarov
Guest
 
Posts: n/a
#5: Sep 8 '06

re: pointer definitions


Jens Theisen wrote:
Quote:
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


Jens Theisen
Guest
 
Posts: n/a
#6: Sep 9 '06

re: pointer definitions


"Phlip" <phlipcpp@yahoo.comwrites:
Quote:
Noah Roberts wrote:
Quote:
typedef int (*(*bar)())();
Ah ja, now I recall..
Quote:
Now don't do it, and use typedefs early and often in production code!
Oooh...
Quote:
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
Closed Thread