Re:Writing a C compiler in 500 lines of Python
by zeusk on Monday September 04, 2023 @10:17PM
(#37387130)
As you note in your edit; we already have to watch for that pitfall :)
so really the best way out is to be as verbose as possible imo; a = a + c or auto nodep = *nodepp; nodep->next;
Compilers and compute performance have grown to make the difference negligible for code output and compilation times but they definitely take a lot of mental complexity out of such scenarios (anything helps when grokking 10k+ lines of code).
Re:Writing a C compiler in 500 lines of Python
by tom_ on Tuesday September 05, 2023 @09:30AM
(#37391393)
I've found struct fields that are pointers far more common than pointers to pointers to structs, so if nothing else it feels like *(p->target) is a more widely useful interpretation of *p->target than (*p)->target would be.
Regarding "n = -5", it would presumably be interpreted as "n=-5", same as today. Operators don't have spaces in them. So "n- -5" is "n-(-5)" (n+5), rather than "n--5" (not valid).
Imagine if we had to watch out for this as a common pitfall:
Even moreso, how would these two lines behave? Would they differ in semantics? Overall, -= is just so much less ambiguous.EDIT: To your point about ->, I personally think C would be better if:
parsed as: instead of: but maybe now I'm not thinking through all the parsing impliciations :)