Earlier quoted context omitted.
> sizeof is a unary operator so the parentheses are rarely necessary I thought parentheses where still required for types, and are optional for variables. Even if that's not so, I still use them for types and avoid them for variables just to add one more cue about what's being sized.
Not "variables," but "expressions." In both C and C++, `sizeof` is a unary operator that applies to a postfix expression, so e.g. `sizeof a[0]` and `sizeof p->x` are both OK. This can theoretically be confusing, although the only examples I know are silly and/or easily fixed: In C++, `p-> pmf` has surprisingly low precedence, so `sizeof p-> pmf` means `sizeof(p) ->* pmf`, which is ill-formed. https://gcc.gnu.org/onli…
Show HN: My C compiler compiled itself
121–130 of 130 posts
Re: Show HN: My C compiler compiled itself
#122Earlier quoted context omitted.
I guess the full bootstrapping process would start with writing a basic compiler in assembly?
The full bootstrapping process starts with entering instructions in binary (or hex or octal) to build an assembler in the first place :)
https://bootstrappable.org/ https://lwn.net/Articles/983340/
Re: Show HN: My C compiler compiled itself
#123Earlier quoted context omitted.
I guess the full bootstrapping process would start with writing a basic compiler in assembly?
It depends on definition of full bootstrapping process. At some point, someone has to bootstrap in raw assembly but we don't need to do that in 2024. If I write a bootstrap compiler in c on a machine that can run c, I can write an alternate backend for any assembly language (that supports the necessary compilation features) and thus produce a compiler implemented in any assembly language without directly writing any…
https://bootstrappable.org/ https://lwn.net/Articles/983340/
Re: Show HN: My C compiler compiled itself
#124https://bootstrappable.org/ https://lwn.net/Articles/983340/
Re: Show HN: My C compiler compiled itself
#125Sounds like you might be someone interested in the Bootstrappable Builds project: https://bootstrappable.org/ https://lwn.net/Articles/983340/
Re: Show HN: My C compiler compiled itself
#126Earlier quoted context omitted.
Saying this is an 'incremental makefile' isn't really correct, as changes to header files aren't going to lead to rebuilding. So, either you need to manually keep references to which .h files you include in your Makefiles up to date, or start worrying about M / MM / MG / MP, and of course you'd like those to be re-run when you change your files, and suddenly your Makefile is an awful lot less simple. This is the main…
You could have taught them `make clean` whenever there's any issues. I work with software engineers and I still have to remind them to try rm -rf ./build/* now and again, which always seems to solve the problem.
Re: Show HN: My C compiler compiled itself
#127Earlier quoted context omitted.
> sizeof is a unary operator so the parentheses are rarely necessary I thought parentheses where still required for types, and are optional for variables. Even if that's not so, I still use them for types and avoid them for variables just to add one more cue about what's being sized.
Not "variables," but "expressions." In both C and C++, `sizeof` is a unary operator that applies to a postfix expression, so e.g. `sizeof a[0]` and `sizeof p->x` are both OK. This can theoretically be confusing, although the only examples I know are silly and/or easily fixed: In C++, `p-> pmf` has surprisingly low precedence, so `sizeof p-> pmf` means `sizeof(p) ->* pmf`, which is ill-formed. https://gcc.gnu.org/onli…
The presence of (int) sort of promotes sizeof from "operator that applies to expressions" to "function that takes a type". I think this is a side effect of reusing the same keyword for two syntactically different constructs.
Re: Show HN: My C compiler compiled itself
#128Earlier quoted context omitted.
I did mention that in other comments, including the C preprocessor helping. make is completely language agnostic, so it cannot “guess” header dependencies. In make, you get the dependencies you specify (whether manual or generated), that’s what I wanted to show.
Make makes the easy part easy but the rest quite hard -- which I think you agree with. It sure would be nice to have something like this: codegen/codegen.o: !codegen/codegen.c $(CC) -c $(CFLAGS) -o $@ $ '!' would run $(CC) with -MD to extract the header dependencies. Doing that back in 1995 would have increased the value and usability of GNU make immensely (and greatly reduced the need for all the other complexity it…
Re: Show HN: My C compiler compiled itself
#129Out of curiosity: would ./30cc_gcc (30cc complied by gcc-hosted 30cc) and ./30cc (30cc complied by self-hosted 30cc) be identical binary files, if 30cc was operating as expected?
No, gcc optimizes code output and can make code shorter and faster. A compiler can make many, many decisions which will show up as differences in the binary output.
Re: Show HN: My C compiler compiled itself
#130Earlier quoted context omitted.
No, gcc optimizes code output and can make code shorter and faster. A compiler can make many, many decisions which will show up as differences in the binary output.
In my question above, both compilers are 30cc, except one of the 30cc's was compiled by gcc and the other self-hosted.
https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_Ref...