3 ms·
turbo pascal is as unsafe as C is, just with more verbose syntax. it has pointers, pointer arithmetic, manual memory allocation, function pointers, casts, unio
by blibble 13y ago
turbo pascal is as unsafe as C is, just with more verbose syntax.
it has pointers, pointer arithmetic, manual memory allocation, function pointers, casts, unions, you name it.
I bet you could write could write 30 odd rules for cpp and then compile your "pascal" with cc, e.g.:
#define begin {
#define end }
#define := =
#define ^ *
#define @ &
and so on
- pjmlp 13y agoNo it is not, because: - It has real strings - Arrays don't decay to pointers - It has reference arguments, which avoid pointer usage for records and out arguments - Requires explicit casts for type conversions, instead of implicit type casts - Provides region allocators, which allow to release a full block of memory in one go - Has real enumerations that don't decay into ints - Allows writing generic code over arrays without requiring the developer to manage a separate length variable - Has proper memory allocation constructs instead of requiring the developer to know the size of memory to allocate Finally, there are other languages in the Pascal family, that provide safety, while allowing for C dirty tricks done explicitly via a system/unsafe package which provides much fine control over the use of said features.
- blibble 13y agoso C doesn't have proper type safe enums (though you could hack those up with typedef + cpp), but does require casts for most type conversions (except those for void*). pascal style strings can be done with the preprocessor, as can generic iterators, allocation for idiots, and "out" function arguments. memory pools are a library feature. and the arrays are the same too, a pointer in pascal can be treated as an infinitely sized array, but the reverse isn't true, just like in C. and, believe it or not, there are other languages in the C family, that provide safety in the same way there are for pascal. tl;dr: pascal and C are more alike than different.
- pjmlp 13y ago> so C doesn't have proper type safe enums (though you could hack those up with typedef + cpp), but does require casts for most type conversions (except those for void*). That still does not make them safe, implicit conversion to int will still happen. > pascal style strings can be done with the preprocessor, as can generic iterators, allocation for idiots, and "out" function arguments. No type safety. > memory pools are a library feature. That aren't part of any C compiler. So you can't count them being available. > and the arrays are the same too, a pointer in pascal can be treated as an infinitely sized array, but the reverse isn't true, just like in C. You lost me there. > and, believe it or not, there are other languages in the C family, that provide safety in the same way there are for pascal. Yes, that is why I use Modern C++, C#, Java, D and will only use C at gunpoint. > tl;dr: pascal and C are more alike than different. True, except in Pascal when bad things happen is because the developer explicitly wanted them to happen. In C everything goes and to have Pascal's safety back, all modern C compilers provide static analyzers. Thus proving a point about the languages design's.