>>106621684
struct Foo; // structs can now be forward declared and it now actually works
int main(void) {
struct Foo memb1 = {0, 1, 2};
// dot operator is no longer used to access struct's member fields
// memb1.x = 3; <-- ERROR
// arrow operator is used for both struct pointers and non pointers
memb1->x = 3;
struct Foo memb2 = {9, 8, 7};
// dot operator is now used to call a priv method (can be stacked, called left to right)
// the result is implicitly returned to tha variable that is calling (memb1 = memb1.func())
memb1.addOne().subtractFields(memb2);
// memb1 fields have now values of {-8, -6, -4} while memb2 remains unchanged
return 0;
}
struct Foo {
int x;
int y;
int z;
// struct definitions can now store function delcarations
// introduce 'priv' keyword as a function type storage modifier
// 'priv' indicates that this function prototype is used:
// static struct Foo addOne(struct Foo memb, ...);
// implicitly returns a member and implicitly takes a member as the first argument
// if a pointer is passed it's dereferenced automatically
priv addOne(void); // void in this case indicates that only the implicit argument is being taken
priv subtractFields(struct Foo memb); // takes two arguments (the first one is implicit)
};
// priv functions can be defined in two ways - explicitly or implicitly
// explicit definition has an explicit type (no priv keyword)
// which obiously makes it possible to call it directly (memb = addOne(memb))
static struct Foo addOne(struct Foo memb) {
memb->x += 1;
memb->y += 1;
memb->y += 1;
return memb;
}