4 ms·
I'll teach function pointers, and might expose them to some style of OO C, but I haven't made any decisions on it. My approach is going to be relatively unflav
by alnayyir 16y ago
I'll teach function pointers, and might expose them to some style of OO C, but I haven't made any decisions on it.
My approach is going to be relatively unflavored by the Macro Hell of other projects. I'd rather not instill those habits. They can learn that on their own time.
I want the learner prepared to write clean sysprog code. That's it, the rest they can learn having been taught proper C and make their own stylistic decisions.
- misham 16y agoWhy would you shy away from macros? Yes they are ugly, but they are an integral part of C and any system programming will rely quite heavily on macros, whether we like it or not. If you're going to cover macros, please make sure to explain how they work and the multitude of pitfalls as well as how to deal with them; which is to wrap each macro in parenthesis.
- alnayyir 16y agoThere are as many potential problems with macros as there are grains of sand in Saudi Arabia. Best not to go there beyond explaining how and why not to, and leave it at that. Order of operations is an example of something that bites people with macros. (ref/deref + macro has nailed a lot of professionals I know)
- dfox 16y agoWell, function pointers are only one aspect of this. Suprisingly many experienced C programmers I've met don't know that you can safely cast pointer to struct to pointer to it's first field, which is pretty important trick to achieve reasonable OO (with real inheritance) in C.
- alnayyir 16y agoI know a line cook that codes C on his free time that would strangle someone who was paid to code that couldn't make a fake object + method calls out of a struct and function pointers.