2 ms·
> C really isn't as great for this as is often suggested either, not for decades at least It's good enough for undergraduate teaching. In C, you can easily ex
by jech 20d ago
> C really isn't as great for this as is often suggested either, not for decades at least
It's good enough for undergraduate teaching. In C, you can easily explain the relation between a struct definition and its layout in memory. It's much more difficult in Caml (what's the relation between an algebraic datatype and its layout in memory?) or Java (which introduces pointers that you never asked for).
We (University of Paris-Cité) are teaching Java in first year, then C and Caml in second year, with seemingly good results.
- pjmlp 20d agoIf the compiler optimizer doesn't reorder the struct fields depending on which flags or pragmas are used, and you could teach that as well in other compiled languages, ignoring the market size of each language.
- tialaramex 20d agoThe C optimizer is not allowed to re-order, so, unless you've specifically used some implementation override you know exactly how C will lay out basic types. Likewise packing isn't allowed by the standard, so you'd again only need to talk about packing if you want to. This seems like a reasonable place to start. Like the way driving school teaches you a U-turn but not a J-turn. Is a J turn actually a thing you might need? Maybe, but it's definitely not where we should start.
- pjmlp 20d agoWell, we cannot talk about ISO C for some things, and Compiler Specific C for others, depending on the convinience of what is being discussed.
- tialaramex 20d agoThe layout rules for C struct are definitely a blessing for teaching I can see that.