Date: Fri, 2 Dec 2022 20:49:52 +0000
> layout stack variables as you are not allowed to compare addresses of
them.
This is a very interesting point. When I raised a question earlier this
year about std::thread behaviour differences between heap and stack objects
I was told that the C++ standard made no distinction between the two types
of memory. In this particular case we seem to be saying that stack
variables in particular require special rules. Is that in effect written
in the standard somewhere for relational operators on pointers?
It is my view that there are potentially many contexts where stack vs heap
is not only relevant but critical and that the standard should not be
silent about them.
Best wishes
David Carter
On Fri, 2 Dec 2022 at 09:31, Marcin Jaczewski via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> czw., 1 gru 2022 o 18:27 Edward Catmur via Std-Discussion
> <std-discussion_at_[hidden]> napisał(a):
> >
> > On Thu, 1 Dec 2022 at 16:58, Vladimir Grigoriev via Std-Discussion <
> std-discussion_at_[hidden]> wrote:
> >>
> >> It is unclear why such a difference between C and c++ was introduced.
> >
> >
> > Yes. If it helps, the difference has existed since standardization: the
> comparison is undefined in C89 and unspecified in C++98, so it might be
> tricky to discover the rationale.
> >
> > Perhaps you could ask SG22 whether they know the cause of the
> divergence, and whether they're interested in resolving it.
> >
>
> This could be required by segmented memory and Far Pointer in 16-bit
> architectures.
> Another could be freedom for compilers how they will layout stack
> variables as you are not allowed to compare addresses of them.
>
>
> >> You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or
> http://ru.stackoverflow.com
> >>
> >>
> >>
> >> Среда, 30 ноября 2022, 22:46 +03:00 от Jens Maurer via Std-Discussion <
> std-discussion_at_[hidden]>:
> >>
> >>
> >>
> >> On 30/11/2022 20.30, Vladimir Grigoriev via Std-Discussion wrote:
> >> > In the C Standard there is explicitly written that when two pointers
> do not point to elements of the same array (including the element or one
> pass the last element) the behavior is undefined:
> >> >
> >> > «In all other cases, the behavior is undefined.»
> >>
> >> > However in the C++ 20 Standard I do not see such a phrase. So is the
> behavior is undefined or unspecified when there are compared two pointers
> to different objects that are not elements of the same array. as for example
> >> >
> >> > &x < &y
> >>
> >> See expr.rel p5. In this case, neither pointer is required to compare
> >> greater than the other by p4, so the result of the relational operators
> >> is unspecified.
> >>
> >> Jens
> >>
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >>
> >>
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >
> > --
> > Std-Discussion mailing list
> > Std-Discussion_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
them.
This is a very interesting point. When I raised a question earlier this
year about std::thread behaviour differences between heap and stack objects
I was told that the C++ standard made no distinction between the two types
of memory. In this particular case we seem to be saying that stack
variables in particular require special rules. Is that in effect written
in the standard somewhere for relational operators on pointers?
It is my view that there are potentially many contexts where stack vs heap
is not only relevant but critical and that the standard should not be
silent about them.
Best wishes
David Carter
On Fri, 2 Dec 2022 at 09:31, Marcin Jaczewski via Std-Discussion <
std-discussion_at_[hidden]> wrote:
> czw., 1 gru 2022 o 18:27 Edward Catmur via Std-Discussion
> <std-discussion_at_[hidden]> napisał(a):
> >
> > On Thu, 1 Dec 2022 at 16:58, Vladimir Grigoriev via Std-Discussion <
> std-discussion_at_[hidden]> wrote:
> >>
> >> It is unclear why such a difference between C and c++ was introduced.
> >
> >
> > Yes. If it helps, the difference has existed since standardization: the
> comparison is undefined in C89 and unspecified in C++98, so it might be
> tricky to discover the rationale.
> >
> > Perhaps you could ask SG22 whether they know the cause of the
> divergence, and whether they're interested in resolving it.
> >
>
> This could be required by segmented memory and Far Pointer in 16-bit
> architectures.
> Another could be freedom for compilers how they will layout stack
> variables as you are not allowed to compare addresses of them.
>
>
> >> You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or
> http://ru.stackoverflow.com
> >>
> >>
> >>
> >> Среда, 30 ноября 2022, 22:46 +03:00 от Jens Maurer via Std-Discussion <
> std-discussion_at_[hidden]>:
> >>
> >>
> >>
> >> On 30/11/2022 20.30, Vladimir Grigoriev via Std-Discussion wrote:
> >> > In the C Standard there is explicitly written that when two pointers
> do not point to elements of the same array (including the element or one
> pass the last element) the behavior is undefined:
> >> >
> >> > «In all other cases, the behavior is undefined.»
> >>
> >> > However in the C++ 20 Standard I do not see such a phrase. So is the
> behavior is undefined or unspecified when there are compared two pointers
> to different objects that are not elements of the same array. as for example
> >> >
> >> > &x < &y
> >>
> >> See expr.rel p5. In this case, neither pointer is required to compare
> >> greater than the other by p4, so the result of the relational operators
> >> is unspecified.
> >>
> >> Jens
> >>
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >>
> >>
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >
> > --
> > Std-Discussion mailing list
> > Std-Discussion_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
-- Mathematics, Modelling, C/C++, Python, Linux, SQL, MATLAB, Mathematica. LinkedIn Profile: https://www.linkedin.com/in/david-carter-a259671a4/
Received on 2022-12-02 20:50:05