How To Check If A Pointer Is In A Range Of Memory -- Raymond Chen

RaymondChenPic.pngC language was defined to cover a large range of computer architectures, including many which would be considered museum relics today. It therefore takes a very conservative view of what is permitted, so that it remains possible to write C programs for those ancient systems. (Which weren’t quite so ancient at the time.)

How To Check If A Pointer Is In A Range Of Memory

by Raymond Chen

From the article:

Suppose you have a range of memory described by two variables, say,

byte* regionStart;
size_t regionSize;

And suppose you want to check whether a pointers lies within that region. You might be tempted to write

if (p >= regionStart && p < regionStart + regionSize)

but is this actually guaranteed according to the standard?

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.