"char (*(*x())[])()
x: function returning pointer to array[] of pointers to function returning char" - K&R, page 122.
Because C is concise and elegant.
Seriously, I am a fan of the language, but this is unforgivable.
Name:
Anonymous2012-01-28 18:18
Use assembly, problem solved.
Name:
Anonymous2012-01-28 18:21
>>2
Look, I am sure there is a better syntax for the same concept than this monstrosity. It might be a bit longer but it does not have to be assembler-long. The above appears like deep magic to people who are not paladins of C.
Name:
Anonymous2012-01-28 18:21
Use assembly, problem solved.
x: function returning pointer to array[] of pointers to function returning char
becomes
x: function returning pointer
Name:
Anonymous2012-01-28 18:21
It looks confusing at first but the rules for reading it are very simple.
Why do you think it's "unforgivable"?
Name:
Anonymous2012-01-28 18:24
>>5
I feel it betrays the very spirit of the language. It is the ugly side of it - the one that eventually lead to the birth of sepples. C should be simple, elegant, and powerful. It is a language that, having studied it for a few hours, you can guesstimate the effect of almost every line of code. Not so for this line, which is counter-intuitive.
well, it's meaning is very consistent. It's not like putting the int inside of operator++(int), which doesn't make any sense, other than for convenient parsing.
You got a function returning char?
char g();
Now an array of pointers to the thing that g's type is? substitute it in where the letter g is:
char (*h[])();
Now a pointer to the thing that h is? put a (*k) where h is:
char (*(*k)[])();
Now a function taking no arguments that returns the type that k is? put a f() where k is:
having studied it for a few hours
It takes 30 sec to learn the rules for reading type signatures of arbitrary complexity. Start within the innermost parentheses around the name, postfix before prefix, left associative for postfix, right associative for prefix.
>>4 x: function returning pointer to array[] of pointers to function returning char becomes x: shit, nigga! I'll have to keep track of types manually and rewrite the function every time I port it to a new architecture
>>9 >>10
I guess I was just overly surprised to see something like this in a language that otherwise avoids such complicated-looking syntax. I realize I am overreacting. I consider the language beautiful, which is why this blemish shocked me.
>>17 http://faydoc.tripod.com/cpu/idiv.htm ID unaffected DF unaffected
VIP unaffected IF unaffected
VIF unaffected TF unaffected
AC unaffected SF undefined
VM unaffected ZF undefined
RF unaffected AF undefined
NT unaffected PF undefined
IOPL unaffected CF undefined
OF undefined
Name:
Anonymous2012-01-29 4:41
if we have
struct point {
int x;
int y;
};
struct rect {
struct point pt1;
struct point pt2;
};
struct rect r, *p = &r;
then these four expressions are equivalent:
&r.pt1.x
&r.pt1
&p->pt1.x
&p->pt1
&(*p).pt1.x
&(*p).pt1
>>23 10/10. Lisp actually has quite extensive print functions too, to which format can expand to, although if you don't want to, you don't have to use them
Name:
Anonymous2012-01-29 6:05
Who the fuck needs a function returning a pointer to an array of pointers to functions returning chars anyway? Code like this should never be written in the first place.
>>25
Maybe not in C, but it makes sense in some high-level languages.
Let me guess an example usage, a function when called returns an array of locale-specific text functions, thus you'd call the function once, based on a global (since no argument was given in >>1), it retrieves the current selected locale, and gives you an array of functions which return all the translated strings (for that locale). Why functions? Maybe some of them could be date/time-like dynamically generated content.
Name:
Anonymous2012-01-29 12:21
>>26
Without closures there is very little point in C. If I did need to return an array of functions I'd probably use an array of pointers to void and cast the individual function pointers closer to the call site.
If that was a bad idea for some reason I'd make a type for for the function pointer.