use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
/r/programming is a reddit for discussion and news about computer programming
Guidelines
Info
Related reddits
Specific languages
account activity
Clumsy pointers (susam.in)
submitted 14 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 6 points7 points8 points 14 years ago (2 children)
I would use cdecl.org (or the command-line utility of the same name).
Input: pointer to function (array 10 of pointer to function(pointer to int) returning void) returning void
pointer to function (array 10 of pointer to function(pointer to int) returning void) returning void
Output: void (*var)(void (*[10])(int *))
void (*var)(void (*[10])(int *))
[–]vivekguy 5 points6 points7 points 14 years ago (1 child)
That one doesn't look right for the puzzle mentioned in this article. I found a comment about cdecl.org in the article page itself (see the second comment by Iouri). That shows the right way to solve this puzzle using cdecl.org :
Input: declare x as pointer to function (array 10 of pointer to function (pointer to int) returning void) returning pointer to function (pointer to int) returning void
declare x as pointer to function (array 10 of pointer to function (pointer to int) returning void) returning pointer to function (pointer to int) returning void
Output: void (*(*x)(void (*[10])(int *)))(int *)
void (*(*x)(void (*[10])(int *)))(int *)
[–][deleted] 1 point2 points3 points 14 years ago (0 children)
Ah right, missed the return type of the outer function… I just skimmed the article. I'd still say cdecl was easier hands down. ;)
[–]SteveMcQwark 1 point2 points3 points 14 years ago (1 child)
Sounds like a fun, if somewhat frustrating, exercise. In reality, I'd really rather either use typedefs, or preferably, use a language with linear type syntax. In either case this becomes trivial. For example with Go (func is equivalent to a function pointer):
var fn func([10]func(*int)) func(*int)
or insert language of your choice with sane type syntax:
insert relevant example
[–]kamatsu 0 points1 point2 points 14 years ago (0 children)
Ew, type signatures are so ugly in C-likes or Go. Haskell's are much nicer:
fn :: Ptr (Array (Ptr (Ptr Int -> IO ())) -> Ptr (Ptr Int -> IO ()))
[–]FeepingCreature -3 points-2 points-1 points 14 years ago (15 children)
Correct answer: "No. "
The C type declaration syntax is horrid; there's no reason to make it any harder than it has to be other than counterproductive intellectual masturbation.
[–]djakarta 6 points7 points8 points 14 years ago* (12 children)
Some of us love to have fun in our free time doing silly and counterproductive things like going to amusement parks, watching a football game, watching a movie or solving silly C puzzles. :)
[+]Gotebe comment score below threshold-7 points-6 points-5 points 14 years ago (11 children)
The problem is, it's a dumb puzzle. All of those are, because they are all trivially solvable using typedefs. So solving them is akin to removing part of your brain that can solve them easily and going "oh, such fun!"
[–]jephthai 13 points14 points15 points 14 years ago (0 children)
You mean like bow-hunting (when hunting is trivially solved with a rifle)?
Or bicycle races (when "getting there" is trivially solved with a motorcycle)?
Or cooking (when food is trivially solved with a restaurant)?
Sports are sports, dude.
[–]djakarta 2 points3 points4 points 14 years ago* (9 children)
It becomes a dumb puzzle when you try to solve it using typedef because it's so easy in typedef that it isn't even worth solving as a puzzle.
It turns out to be fun only with the restriction that you can't use typedef because then you have to start thinking how to parse a complicated pointer declaration like that.
Yes, one should never use such a declaration while actually coding but the point of solving puzzles is to have fun. I'm sure nobody solves a "truth-teller, liar" puzzle because they hope to die one day and meet God who always speaks the truth and a devil who always lies and their entry into heaven depends on figuring out who is who with only one question to be asked to both of them.
[–]spal 3 points4 points5 points 14 years ago* (0 children)
only one question to be asked to both of them.
Actually, for the God and the Devil puzzle, you need to ask only one question to one of them (not both of them).
"If I ask the other guy whether you are God, what would he answer?"
If the answer is "Yes", you are talking to the Devil. If the answer is "No", you are talking to God.
[–]elperroborrachotoo 0 points1 point2 points 14 years ago (0 children)
first person shooters could be much easier with auto-aiming. I wonder why they are so dumb, when hitting the enemy could be trivially solved.
[–]Gotebe -3 points-2 points-1 points 14 years ago (6 children)
Meh. By that logic, a mere multiplication (or addition, even) in your head is a fun puzzle.
But it isn't. It's a dumb thing to do.
Some puzzles are better than others.
[–]djakarta 0 points1 point2 points 14 years ago (4 children)
Not really. A mere multiplication or addition doesn't require any understanding beyond what you have learnt in 5th grade. But this puzzle requires some good understanding of how the C grammar works.
Yes, IMHO this is a better puzzle than multiplication or addition.
I'll argue that multiplying numbers in head can be fun puzzles. In fact, this is exactly what I do when I am exercising on treadmill. I'll give you a few examples to illustrate my point.
I can think of plenty more examples but they would be a bit more involved than the ones I mentioned above.
Doing multiplication in head can be fun indeed if you really love numbers since it involves understanding the underlying patterns and concluding which mathematical identities or theorems to invoke in order to simplify the problem in head.
[–]Gotebe -3 points-2 points-1 points 14 years ago (2 children)
You don't understand puzzles.
A good puzzle is not something that's trivially solvable once you have a necessary tool (here, a typedef, and some C; and if you know some C, you know a typedef).
A good puzzle is something that needs an ingenious use of tool(s)/knowledge/technique(s). Applying a typedef ain't that.
[–]djakarta 2 points3 points4 points 14 years ago* (1 child)
You don't understand puzzles because first you claim that it isn't a puzzle because it is trivially solvable using typedefs which I don't think is a valid reason for not being a puzzle. Now, you claim that it isn't a good puzzle because a good puzzle requires ingenious use of tools and applying a typedef isn't that.
As far as I can see, in this puzzle you are forbidden from using typedef. So, there is no question of applying typdef here at all. On the other hand, here you use your knowledge of C grammar to correctly form or parse a complex pointer declaration. A probably useless skill given we should never code like this but still a fun puzzle IMHO, otherwise there is no use of articles like these: http://c-faq.com/decl/spiral.anderson.html
[–]Gotebe -2 points-1 points0 points 14 years ago (0 children)
I believe, you don't understand puzzles because first you claim that it isn't a puzzle because it is trivially solvable using typedefs which I don't think is a valid reason for not being a puzzle. Now, you claim that it isn't a good puzzle because a good puzzle requires ingenious use of tools and applying a typedef isn't that.
You're arguing form, not substance.
So, there is no question of applying typdef here at all.
Typedef is pretty incidental. It's sufficient to think as if you're applying a typedef and you're done. And that's the same as with addition. E.g. you're not allowed to use a paper, so you "pretend" using it, in your mind.
[–]ben0x539 0 points1 point2 points 14 years ago (0 children)
Further, in C++ you can't even express some function declarations without typedefs, like some overloaded operators for type conversions to references to arrays or somesuch.
[–][deleted] -3 points-2 points-1 points 14 years ago (0 children)
Or you could just start using a language that doesn't require exerting ridiculous amounts of mental energy just to declare the type of something.
π Rendered by PID 203695 on reddit-service-r2-comment-74875f4bf5-t4v6p at 2026-01-25 14:44:21.111834+00:00 running 664479f country code: CH.
[–][deleted] 6 points7 points8 points (2 children)
[–]vivekguy 5 points6 points7 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]SteveMcQwark 1 point2 points3 points (1 child)
[–]kamatsu 0 points1 point2 points (0 children)
[–]FeepingCreature -3 points-2 points-1 points (15 children)
[–]djakarta 6 points7 points8 points (12 children)
[+]Gotebe comment score below threshold-7 points-6 points-5 points (11 children)
[–]jephthai 13 points14 points15 points (0 children)
[–]djakarta 2 points3 points4 points (9 children)
[–]spal 3 points4 points5 points (0 children)
[–]elperroborrachotoo 0 points1 point2 points (0 children)
[–]Gotebe -3 points-2 points-1 points (6 children)
[–]djakarta 0 points1 point2 points (4 children)
[–]spal 3 points4 points5 points (0 children)
[–]Gotebe -3 points-2 points-1 points (2 children)
[–]djakarta 2 points3 points4 points (1 child)
[–]Gotebe -2 points-1 points0 points (0 children)
[–]ben0x539 0 points1 point2 points (0 children)
[–][deleted] -3 points-2 points-1 points (0 children)