Re: Fast and Safe C Strings: User friendly C macros to Declare and use C Strings.



Obviously, there are two streams of thought here, those that think there is a problem, and those that don't. And some people think that there is a C string type.

Those that say there isn't a problem, and that it is the programmer's fault perhaps have forgotten that seat belts were introduced into cars (and variable crumple rates) to protect people if an accident happens. It is true that an accident is caused by cars (well, most cars...) but rather the driver. And it is precisely because drivers do cause accidents, we have safer cars. Indeed, cars handle much better than they used to, and have many more safety features built in. And computer languages should be safer, rather than not (safer). We ALL make mistakes!

And for those people that suggest that C does have a string type, I would suggest that it doesn't, compared with Pascal, PL/I, COBOL or even Assembler. It has an array of characters, which is quite different from a string.

For example, in PL/I, one could write:

Dcl String10 char(10) varying;
Dcl String20 char(20) varying init
('Long 20 Character XX');


String10-string20;

This will automatically truncate the result, rather than copy the 20 bytes and overwrite adjacent storage, as in C.

And so naturally, I agree with those that say there is a problem.


What is needed is for ANSI to bite the bullet and fix the problem. Or for someone big, like IBM to do it, and force a standard change. (As an aside, there is a language called D, which has a length word for strings, I believe. It is written by Walter Bright, who wrote the original Zortech C compilers. Bright by name, bright by nature... I think it uses the GCC C compiler as a backend.)

But I shall write to ANSI now. Again, I think....

The thing is that there is quite a lot of straight C code making it's way into IBM's Z/OS at the moment. And it should take into account these performance robbing routines, because mainframes usually run thousands of programs at once, rather than the tens or hundreds that a Linux box might. Therefore, overheads need to be kept to a minimum (as they should always be...).


Clem


.



Relevant Pages

  • Re: Accelerating rocket/light beam question
    ... There is a string connecting the two cars. ... Think, for a moment, about a system consisting of two rockets B and C ... F be the frame of your cars. ...
    (sci.physics.research)
  • Serialization of a custom collection
    ... public class CarCollection: List ... private string errMsg; ... CarCollection cars = GetCars; ... How to properly enhance my custom collection? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: session variable issue?
    ... You are never assigning Sessionto anything. ... You are setting the string "cars" to 'Y', but since never assign the Session ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: web service error - urgent
    ... When I try and run it Im' getting the following error message: ... Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) ... Cars car = new Cars ... public string make; ...
    (microsoft.public.dotnet.framework.webservices)
  • RE: web service error - urgent
    ... What is "ports" anyway? ... What about this instead (return an array of Cars): ... Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id) ... public string make; ...
    (microsoft.public.dotnet.framework.webservices)