In c99, my understanding is that comparing two pointers which do not point within the same aggregate results in undefined behavior. Given an aggregate A, a pointer p_good which is known to point within A, and a pointer p_unknown which may or may not point within A, is it possible to construct a portable test with defined behavior which determines whether it is safe to compare p_good and p_unknown?
Obviously, this test cannot itself fall afoul of the restrictions on comparing pointers.
I suspect that the answer is 'no', but I'd be happy to be shown otherwise.