4 ms·
Yes, there is a less powerful subset of C that is memory safe. You can use local variables, but no pointer types - no variables with pointer types, no function
by tacostakohashi 8y ago
Yes, there is a less powerful subset of C that is memory safe.
You can use local variables, but no pointer types - no variables with pointer types, no functions that return a pointer type, and don't use the * or & operations which dereference or create a pointer.
Initialize everything - there are compiler warnings to help with that.
Admittedly, this subset of C isn't particularly useful. No dynamic memory, no strings or file i/o since those functions from the standard library take pointers. You could definitely do some arithmetic and return the value from main() in a completely memory-safe manner using this subset, though.