Groups | Search | Server Info | Login | Register


Groups > comp.std.c > #6650

Re: May a string span multiple, independent objects?

From James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups comp.std.c
Subject Re: May a string span multiple, independent objects?
Date 2024-07-03 12:11 -0400
Organization A noiseless patient Spider
Message-ID <v63t7d$28fl8$4@dont-email.me> (permalink)
References <20240703141500$00ed@vinc17.org> <lel8ndF7f8iU1@mid.dfncis.de>

Show all headers | View raw


On 7/3/24 11:23, Hans-Bernhard Bröker wrote:
> Am 03.07.2024 um 16:31 schrieb Vincent Lefevre:
>> ISO C17 (and C23 draft) 7.1.1 defines a string as follows: "A string
>> is a contiguous sequence of characters terminated by and including
>> the first null character."
>>
>> But may a string span multiple, independent objects that happens
>> to be contiguous in memory?
>>
>> For instance, is the following program valid and what does the ISO C
>> standard say about that?
> 
> Comparing pointers pointing at distinct objects is already invalid (for 
> some interpretation of "invalid")

Comparison of valid pointers that point at distinct objects has
well-defined behavior. Such operations would be pretty useless if that
weren't the case, since they only compare the locations of those objects
- if they were allowed only for objects that are  not distinct, the
locations would necessarily be the same, so, ==, <= and >= would always
return true, and !=, <, and > would always return false.

Furthermore, comparison for equality (as opposed to comparison for
relative order) is permitted even for objects that aren't sub-objects of
the same larger object. The problems with such code involves
incrementing and dereferencing such pointers, not comparing them.

Back to comp.std.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

May a string span multiple, independent objects? Vincent Lefevre <vincent-news@vinc17.net> - 2024-07-03 14:31 +0000
  Re: May a string span multiple, independent objects? Hans-Bernhard Bröker <HBBroeker@gmail.com> - 2024-07-03 17:23 +0200
    Re: May a string span multiple, independent objects? Vincent Lefevre <vincent-news@vinc17.net> - 2024-07-03 15:37 +0000
    Re: May a string span multiple, independent objects? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-03 12:11 -0400
    Re: May a string span multiple, independent objects? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-08 08:51 -0700
  Re: May a string span multiple, independent objects? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-03 11:59 -0400
    Re: May a string span multiple, independent objects? Ben Bacarisse <ben@bsb.me.uk> - 2024-07-03 22:08 +0100
      Re: May a string span multiple, independent objects? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-03 17:36 -0400
      Re: May a string span multiple, independent objects? Vincent Lefevre <vincent-news@vinc17.net> - 2024-07-04 13:22 +0000
        Re: May a string span multiple, independent objects? Ben Bacarisse <ben@bsb.me.uk> - 2024-07-05 05:14 +0100
        Re: May a string span multiple, independent objects? James Kuyper <jameskuyper@alumni.caltech.edu> - 2024-07-05 01:37 -0400
        Re: May a string span multiple, independent objects? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-08-08 08:35 -0700
  Re: May a string span multiple, independent objects? Kaz Kylheku <643-408-1753@kylheku.com> - 2024-07-05 07:14 +0000

csiph-web