Re:Introduction to Compilers and Language Design (2021)
by dunefox on Wednesday May 18, 2022 @08:26AM
(#31421905)
With C you need to pay attention to things like manual memory management which aren't necessary with other languages or to understand the material.
[ Parent
| on HN ]
Re:Introduction to Compilers and Language Design (2021)
by s_dev on Wednesday May 18, 2022 @10:55AM
(#31423564)
Aye but these lads are building a compiler. Probably shouldn't hide things like 'memory management' at the introduction stage as use of memory is inherent to all computing and programming.
Re:Introduction to Compilers and Language Design (2021)
by dunefox on Wednesday May 18, 2022 @11:06AM
(#31423713)
Sure, that makes sense, but you can write a compiler in languages that don't require it themselves. That's what I meant.
Re:Introduction to Compilers and Language Design (2021)
by arinlen on Wednesday May 18, 2022 @05:04PM
(#31427642)
> Sure, that makes sense, but you can write a compiler in languages that don't require it themselves.
I don't follow your rationale. With C the developer manages heap memory by basically calling malloc and free.
This means that once you have the memory model set, all you need to do to roll your compiler is to implement the interface.
A language that "don't require it themselves" is a language which provides only high level constructs and dumps all the memory management logic to the compiler/runtime, from object allocation/deallocation to lifetime management.
How is that simpler to pull off by a compiler writer?
Re:Introduction to Compilers and Language Design (2021)
by Koshkin on Wednesday May 18, 2022 @07:51PM
(#31429021)
The target language generally has nothing to do with the language of the compiler, where automatic memory management is just as useful (and also helps to minimize the amount of unrelated technical detail) as anywhere else.
Re:Introduction to Compilers and Language Design (2021)
by programmer_dude on Wednesday May 18, 2022 @09:31AM
(#31422536)
Manual memory management is optional. IIRC some version of the D compiler was written assuming an infinite virtual address space (basically they just did not bother calling free() ever)!
Re:Introduction to Compilers and Language Design (2021)
by duped on Wednesday May 18, 2022 @11:12AM
(#31423797)
There's a chapter in the book dedicated to memory layout of programs that discusses program segments, paging, implementation of malloc/free, etc that is more or less required before getting to the assembler and codegen stages.
Even if you can write a compiler assuming infinite memory that generates programs that also assume it, it would be a disservice to readers to ignore that for brevity. It's an important part of understanding how programs are created.