Re: Horses & water



In article <i9055q$a5s$5@xxxxxxxxxxxxxxxxxxxx>, Johnny Billquist <bqt@xxxxxxxxxx> writes:

Heck! The standard more or less makes sure you cannot do that.
Pointer arithmetic is legal, and used, and can point to anywhere inside,
or outside what you might think is meaningful, and still be legal.

You don't want to break this, believe me.

You can accomplish this in Fortran via out of range indexes. And
you can turn on and off the compiler and run time checks to make
sure you don't, if you have a good compiler. But language
rules help you not overflow string buffers by simply requiring
behavior that tracks the allocated (not used) length of strings
(you can allways call LEN() on a CHARACTER variable).

And in general, I do want to break it. I want to find the incipient
bugs in programs. I know of exceptions to that rule and its good
to be able to handle the exceptional circumstances, but not by
making them the rule.


I've seen folks claim that it's not the fault of the language that
compilers don't do this. The langauge standard does require null
terminated strings, but does not require that they be simply
passed by reference. But nothing ever gets added to the standard
that isn't met by passing them by reference, so compiler writers
won't do it.

To me, that's a fault of the language.

Yes, in C, there is a requirement that they be passed by reference. Or
rather, C don't pass strings at all. It only passes pointers. And the
pointers are actually passed by value.
The problem though, is that strings are just random pointers in C.

I've seen lots of behavior in C that is required and met by pass
by reference, but I have not seen an explicit requirement that
additional information cannot be passed.

.



Relevant Pages

  • Re: Horses & water
    ... and the program operations on the byte array would remain the same. ... that isn't met by passing them by reference, ... C don't pass strings at all. ... And the pointers are actually passed by value. ...
    (comp.os.vms)
  • Re: c# features
    ... unsafe operations removed. ... We were talking about whether the existing feature "pointers" satisfy the ... need for returning a reference to a value type instance on the heap. ... it just isn't included in the standard. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: F77/C integration : strings
    ... >subroutine from Fortran 77, since afaik there's no concept for pointers? ... Standard Fortran 77 has no explicit ... >need to read from a file some arbitrary length strings, ...
    (comp.lang.fortran)
  • Re: the first programming language: C
    ... In C, except from simulating call by reference, the only situations ... where we really need pointers in high level application programming is ... one possibility would be to essentially intern all the strings, ...
    (comp.lang.c)
  • Re: Array of Strings
    ... >What I would like to do is create an array of strings. ... I would like to create an array of char* 's. ... >only catch is that I will need to pass the array by reference to ... Although from my understanding of pointers, ...
    (comp.lang.cpp)