Re: trim whitespace

John Kelly <jak@xxxxxxxxxxxx> writes:

On Wed, 25 Aug 2010 13:47:21 +0100, Ben Bacarisse <ben.usenet@xxxxxxxxx>

John Kelly <jak@xxxxxxxxxxxx> writes:
You are thinking of C strings. There are no "bounds" to a pointer.

There are, both in theory and in practise.

I meant, a pointer can wrap to 0, and if your data has no terminating
\0, the pointer won't stop you either. You have a theoretical infinite

Yes, I know this is what you meant. I was referring to the bounds
within which you must keep to have defined behaviour.

When I originally asked you to say what the contract was between the
caller and the callee, this was one of the things that you could ave
specified: the code works only on such-and-such type machines. In
effect you did specify that when you said the contract is defined by
what the code does. I.e. you wrote trim for machines where it works

Aside from the ptrdiff_t issue, how can it fail?

It could do all manner of things. For example, it might trim a string
that belongs to another process or thread. It might write it's trimming
null into a memory-mapped register that does almost anything you can
think of.

and, presumably, you don't care about ones where it won't.

Segfaulting is a caller's error, not a defect in trim(). What other
failure scenario is there?

All of the above are caller errors but they make it hard to defend the
idea that the function is bullet-proof or has no undefined behaviour.

Why not save yourself some trouble and define whatever happens when the
pointer "wraps" as a caller error and then you can be done with this?


Relevant Pages

  • Re: Safe pointer arithmetic and typecasts :D
    ... > to something else, though, you should use a pointer of that type. ... I assume delphi will always allow a programmer to ... > don't get any overflow when doing pointer arithmetic. ... Why doesn't delphi just wrap it? ...
  • Re: function pointer in JNI
    ... > The c library I am using requires passing in a pointer to a user ... I am wondering how to wrap that in JNI. ... obviously you have to pass it a pointer to a regular C ...
  • Re: How to crash Safari
    ... > pointer over the list. ... > which forces a line wrap, ... Prev by Date: ...
  • RE: How to get the main frame window from a doc class?
    ... > I have a SDI application, and would like to create a working thread when ... To send message to the main frame window to show what ... I used following code to wrap the pointer: ...
  • Re: Interrupt driven UART
    ... Most UART drivers/ISR use a circular queue and just move pointers around ... FIFO and a circular queue? ... that may or may not have "wrap around" in the memory pointer ... you may not be able manipulate the data pointer directly. ...