I was trying to implement vector algebra with generic algorithms and ended up playing with iterators. I have found two examples of not obvious and unexpected behaviour:
- if I have pointer
pto a struct (instance) with fieldfi, I can access the field as simply asp.fi(rather thanp.*.fi) - if I have a "member" function
fun(this: *Self)(whereSelf = @This()) and an instancesof the struct, I can call the function as simply ass.fun()(rather than(&s).fun())
My questions are:
- is it documented (or in any way mentioned) somewhere? I've looked through both language reference and guide from ziglearn.org and didn't find anything
- what is it that we observe in these examples? syntactic sugar for two particular cases or are there more general rules from which such behavior can be deduced?
- are there more examples of weird pointers' behaviour?