r/cprogramming • u/Yaster- • May 04 '26
What does an overlap mean exactly?
I've given myself a headache trying to understand what an overlap is after watching a video about the restrict key word, I also struggled to figure out what aliasing is, but i know what it is now(when an address variable stores the memory address that another also stores ), however with overlap I can't wrap my head around it.
I've looked online for an explanation and my current understanding feels wrong still
Does it occur when you store a range of memory in two different address variables and some of the addresses that are stored in one are also stored in another? Is that only one kind of overlap?
Either way that just seems like aliasing to me, whats the difference?
8
u/EpochVanquisher May 04 '26
I think I understand what you are getting at…
The two regions overlap because they both contain the elements at indexes 1-8. Yes, this is also a type of aliasing.
In the above scenario, you have to use memmove() instead.
2
u/flatfinger May 05 '26
The intention of restrict is to allow a compiler to assume that, during the lifetime of a restrict-qualified pointer P, at least one of the following will be true of every byte of storage throughout the universe:
Nothing in the Standard nor Rationale suggests any implications regarding the relative positions of storage accessed via different means, provided that each and every individual byte throughout the universe satisfies at least one of those conditions.
Unfortunately, rather than recognize the existence of pointers whose derivation cannot be proven (accesses via which would be allowed under #2 or #3) the Standard uses a hand-wavy definition of "based upon" which completely falls apart if a restrict-qualified pointer is observed to equal an address that is not based upon it.