My primary programming language, j, was recently open-sourced. In order to improve it, I'm studying the source, which is written in C.
But it's been a long (!) time since I've read or written C, and I wasn't even good at it then. And the way this particular codebase is written is ... idiosyncratic (many APL interpreters, J among them, have their source written in high-level "APL style", even when written in a low-level language; very terse, redundancy eschewed, heavy macro use, etc.)
At the moment, I'm trying to understand the fundamental data structures it employs. The most fundamental one is the typedef A
("A" is for "array"):
typedef struct {I k,flag,m,t,c,n,r,s[1];}* A;
which I understand fine. But I'm struggling to wrap my head around what AF
is, two lines later:
typedef A (*AF)();
What does this syntax mean? In particular, what does it mean when things are later declared as "type AF"? Is an AF
simply a pointer to an A
?
My immediate goal is to interpret memory dumps which include things of type V
(for "verb"), whose first two members are AF
s:
typedef struct {AF f1,f2;A f,g,h;I flag,mr,lr,rr,fdep;C id;} V;
but my overall goal is larger than that, so please elaborate on the syntax employed in the definition of AF.
AF
is a pointer to a function that takes no parameters and returnsA
. – ValineA
. Very likely it should be defined astypedef A (*AF)(void);
. If it's really meant to take an arbitrary number of arguments, then you can very easily have undefined behavior by calling a function incorrectly, with no diagnostic from the compiler. – Seemaseeming()
takes a fixed but unspecified number of arguments. The corresponding definition determines the actual number and type(s) of the parameters. This is an obsolescent feature. A variadic function, likeprintf
, is declared/defined with, ...
, and takes N fixed arguments plus 0 or more ... – SeemaseemingA func(A)
andA func(A, A)
; these would be two distinct functions that happen to have the same name. C doesn't have overloading, but you could defineA func1(A)
, andA func2(A, A)
. (I don't know J, so I can't comment on how it works.) – Seemaseeming