3 ms·
The proposed replacement doesn't actually have the same semantics as restrict. I believe that Pascal knows this, as he's a smart guy. Consider memcpy; its arg
by stephencanon 14y ago
The proposed replacement doesn't actually have the same semantics as restrict. I believe that Pascal knows this, as he's a smart guy.
Consider memcpy; its arguments are declared restrict. This not only means that the source and destination pointers cannot be the same (which is what Pascal's "replacement" says), but also means that the buffers cannot overlap at all (i.e. the src pointer cannot be anywhere in the range [dst-(length-1), dst+(length-1)]).
restrict also has the virtue of making this contract apparent to your callers, as it's part of the API. People should know that they can't call memcpy with overlapping buffers, and use memmove instead. If the information is instead encoded in a cryptic line in the implementation, then it isn't obvious to a developer who intends to use the function.
- pascal_cuoq 14y agoI find your explanation about “restrict” being part of the function interface extremely insightful. Just that makes my misguided attempt at humor worth it (for me). The idea was in gioele's comment too but you made me understand it.
- pascal_cuoq 14y agoI thought subscribers to the blog deserved to see that comment, so I wrote an answer/advertisement: http://blog.frama-c.com/index.php?post/2012/07/25/The-restrict-qualifier-as-an-element-of-specification http://blog.frama-c.com/index.php?post/2012/07/25/The-restri...