3 ms·
Don't you think that pascal's standard safeties will prevent mistakes ? 1) array bounds checking (which can be used for safe hardware access instead of peek/po
by waps 13y ago
Don't you think that pascal's standard safeties will prevent mistakes ?
1) array bounds checking (which can be used for safe hardware access instead of peek/poke)
2) pascal-style strings (with actual support for them, both in the language and in the standard library) (meaning a missing \0 doesn't erase the entire memory)
3) type-safe pointers
4) no pointer arithmetic
5) no preprocessor
...
- pjmlp 13y agoAdditionally all those safety mechanisms can be turned off for performance, but only on the exact spot where it really matters, instead of being scattered all around the code.
- weland 13y ago> 1) array bounds checking (which can be used for safe hardware access instead of peek/poke) How? Peek/poke at the wrong address will generate an error in any case, and any MMU-less platform worth using will have the memory-mapped peripherals into a lower region, where it doesn't get thrashed by writing past the end of a buffer. I have seen bugs occurring because of data located past a buffer getting thrashed, but I don't remember seeing one in the context of hardware access. > 2) pascal-style strings (with actual support for them, both in the language and in the standard library) (meaning a missing \0 doesn't erase the entire memory) That shouldn't happen in C, i.e. there are library routines you should use so that it doesn't happen. Not that string processing isn't a pain :-). > 3) type-safe pointers No complaints here :-) > 4) no pointer arithmetic That's not always good, but it does decrease the likelihood of certain types of bugs, so yep! > 5) no preprocessor Also yep :)
- acqq 13y ago2) "That shouldn't happen in C" It happens every day and it will as long as there's C. Zero-terminated strings are part of the standard library and almost infinite number of other libraries. You can't pretend it doesn't exist as the most common convention. For 1) see waps' comment with byte absolute. One complete program from that time which uses that feature: http://kd5col.info/swag/INTERRUP/0019.PAS.html http://kd5col.info/swag/INTERRUP/0019.PAS.html
- waps 13y agoExample of absolute array: var EGAVGAScreen : Array[0..41360] of Byte absolute $A000:0000; Et voila : bounds-checked memory mapped hardware access. (note: the very well known "Crt" unit uses a memory mapped video buffer like this. So if you programmed a turbo pascal program, chances were good it was using this trick for screen output. Advantage : the speed is unbeatable)