3 ms·
$ sudo apt install cdecl […] $ cdecl Type `help' or `?' for help cdecl> explain char *(*(**foo[][8])())[]; declare foo as array of array 8 of pointer
by teddyh 2y ago
$ sudo apt install cdecl
[…]
$ cdecl
Type `help' or `?' for help
cdecl> explain char *(*(**foo[][8])())[];
declare foo as array of array 8 of pointer to pointer to function returning pointer to array of pointer to char
cdecl>
- pquki4 2y agoWow, nice. Now I think every IDE should come with this...
- samatman 2y agoThought I'd take a crack at it in Zig: const foo: [_][8]**fn () [*][*:0]const u8; This is an array of result-defined size, of arrays of eight pointers to fn pointers, which returns a many-item pointer to null-terminated arrays of u8. Null terminated because we're going to assume that the C data structure is properly null-terminated... Still an insane data structure, and I'm still learning Zig, so I can't promise this is precisely equivalent to the C, I got as close as I could and am unwilling to try and compile, let alone build, such a type. No one would actually do this unless they needed `extern` compatibility. Ignoring the fact (pointed out in the Fine Article) that no one would use anything vaguely like this, a more Zig native version might be const foo: [_][8]**fn() [][]const u8 Which returns a slice of slices of immutable u8s, these being fat pointers which include their length.
- xigoi 2y agoNim equivalent: seq[array[8, ptr ptr proc(): ptr seq[ptr char]]]] I love having actual words instead of random punctuation soup.
- asimeqi 2y agoWhy do I remember The C Programming Language book by K&R explaining how to write a version of cdecl? I just checked the second edition of the book and my memory seems to be wrong.
- sea6ear 2y agoIt's not listed as cdecl and (therefore?) not findable in the index, but in chapter 5 - Pointers and Arrays - the book presents the programs dcl and undcl that translate between C declarations and English renderings of them. I believe dcl mimics the cdecl program.
- WalterBright 2y agoD Language: char*[]*function()[8][] foo;
- deleted 2y ago[deleted]
- nuancebydefault 2y agoI think brackets are needed in the sentence, otherwise it is ambiguous?