Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > substring

Reply
Thread Tools

substring

 
 
Dan Pop
Guest
Posts: n/a
 
      11-10-2003
In <(E-Mail Removed)> Jeremy Yallop <(E-Mail Removed)> writes:

>Dan Pop wrote:
>> In <(E-Mail Removed)> Jeremy Yallop <(E-Mail Removed)> writes:
>>
>>>Perhaps, but I was responding to the claim that:
>>>
>>> puts and printf are different because puts prints a string, while
>>> printf explicitly takes a null terminated array.
>>>
>>>A null terminated "array" in the library section is no different from
>>>a string. In particular, the address computations that can be
>>>performed on each are precisely the same.

>>
>> This is the root of your misunderstanding.

>
>I prefer "This is the point under discussion".


I've made that point far too often in this discussion and no one could
provide a quote from the standard proving me wrong. By that time, you
should have gotten it, hence my actual wording.

>> The definition of array you have quoted yourself *explicitly*
>> requires pointer arithmetic to work inside the array.
>>
>> The definition of string contains NO such requirement:

>
>You may be right, although that would make "contiguous" a rather
>unhelpful word to describe the bytes that contain a string.


It's helpful enough in deciding whether s1 (in your previous example)
can be used where a string is expected or not.

>If two
>pointers into a string cannot be compared for equality and if no valid
>pointer arithmetic on one will yield a pointer equivalent to the other
>then the bytes aren't contiguous in any useful sense. Just to be
>clear, though, are you claiming that in the following:
>
> #include <string.h>
> char *strcpy(char * restrict s1, const char * restrict s2);
>
> The strcpy function copies the string pointed to by s2 (including
> the terminating null character) into the array pointed to by s1.
>
>`s1' *must* point to a single object, whereas `s2' may point to two
>adjacent objects spanned by a single string?


Precisely. This is what the standard says, with no room for an alternate
interpretation. All the relevant quotes already provided in this thread.

>>> A direct consequence of this anomaly is that NO function expecting a

>> string parameter that is not explicitly required to be contained in an
>> array, cannot be *portably* implemented in C, because a C implementation
>> would necessarily rely on pointer arithmetic working inside the string.
>> But the definition of string quoted above provide no such guarantee.

>
>Again, you may well be right according to the letter of the standard
>but that this sort of absurdity is a consequence shows (to me) that
>this is not its intent.


I agree that the actual standard wording is sloppy and that it *probably*
does not reflect the intent. But this doesn't make any shred of a
difference: until fixed, it is the current wording that rules what is
allowed and what is not allowed.

OTOH, there might be a non-obvious reason the standard is worded this way.
When I posted this question to comp.std.c (about half a year ago), nobody
provided any useful insights.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Jeremy Yallop
Guest
Posts: n/a
 
      11-10-2003
Dan Pop wrote:
> I agree that the actual standard wording is sloppy and that it *probably*
> does not reflect the intent. But this doesn't make any shred of a
> difference: until fixed, it is the current wording that rules what is
> allowed and what is not allowed.


Perhaps a defect report is called for. How would you suggest
resolving the inconsistency? Fixing the definition of string to
preclude spanning non-overlapping objects seems like the obvious
solution.

> OTOH, there might be a non-obvious reason the standard is worded this way.
> When I posted this question to comp.std.c (about half a year ago), nobody
> provided any useful insights.


In <news:ag447l$t62$(E-Mail Removed)>? Yes, I see what you mean.

Jeremy.
 
Reply With Quote
 
 
 
 
Dan Pop
Guest
Posts: n/a
 
      11-10-2003
In <(E-Mail Removed)> Jeremy Yallop <(E-Mail Removed)> writes:

>Dan Pop wrote:
>> I agree that the actual standard wording is sloppy and that it *probably*
>> does not reflect the intent. But this doesn't make any shred of a
>> difference: until fixed, it is the current wording that rules what is
>> allowed and what is not allowed.

>
>Perhaps a defect report is called for. How would you suggest
>resolving the inconsistency? Fixing the definition of string to
>preclude spanning non-overlapping objects seems like the obvious
>solution.


I entirely agree. I can't see any problems created by explicitly
requiring that each C string is stored inside a C object. But even then
we could discuss about the validity of:

struct { char s1[3], s2[4]; } foo = {"abc", "def"};

if (foo.s1 + sizeof foo.s1 == foo.s2) puts(foo.s1);

Is the fact that the string is entirely contained in the foo object
enough? In my opinion it should be, but people like JW might disagree...

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding a SubString within a String Badass Scotsman ASP .Net 2 03-31-2006 04:00 PM
RegEx search for a substring within a substring colinhumber@gmail.com Perl Misc 3 08-03-2005 04:29 PM
find if there is a given substring inside a string juli ASP .Net 3 12-06-2004 11:52 AM
web sddress substring =?Utf-8?B?Sm9u?= ASP .Net 2 11-30-2004 01:31 PM
"Substring" for images? How do I determine if an image is contained within another? Sean Java 0 05-04-2004 05:50 PM



Advertisments