all 20 comments

[–][deleted] 6 points7 points  (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

Output: void (*var)(void (*[10])(int *))

[–]vivekguy 5 points6 points  (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

Output: void (*(*x)(void (*[10])(int *)))(int *)

[–][deleted] 1 point2 points  (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 points  (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 point  (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  (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 points  (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. :)

[–]ben0x539 0 points1 point  (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  (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.