4 ms·
I disagree with your premise. C was designed to be a high level (for its time) language, abstracted from actual hardware >It's pretty much a tiny wrapper aroun
by poincaredisk 2y ago
I disagree with your premise. C was designed to be a high level (for its time) language, abstracted from actual hardware
>It's pretty much a tiny wrapper around assembler
Assebler has zero problem with adding "null + 4" or computing "null-null". C does, because it's not actually a tiny wrapper.
- jbverschoor 2y agoNot high-level.. Portable. Portable layer above assembler/arch. NULL doesn't exist in assembler, and in C, NULL is only a defined as a macro. It's not something built-in. C doesn't have any problems adding 4 to NULL nor subtracting NULL from NULL.
- jbverschoor 2y ago#include <stddef.h> int main() { if (NULL + 4) {} if (NULL - NULL) {} return 0; }
- teo_zero 2y ago> C doesn't have any problems adding 4 to NULL nor subtracting NULL from NULL. "Having problems" is not a fair description of what's at stake here. The C standard simply says that it doesn't guarantee that such operations give the results that you expect. Also please note that the article and this whole thread is about the address zero, not about the number zero. If NULL is #defined as 0 in your implementation and you use it in an expression only involving integers, of course no UB is triggered.