Wow Dan, this is news for me. No kind of pointer?
Not even a char * as it seems?
Not even.
Strange. Are all those prototypes in string.h wrong?
Nope, they are correct. But they are not passed the representations of
strings, they are passed the addresses of strings. This is where pointers
get into the picture.
I would fill a defect report.
Just do not exaggerate Dan. Let's keep cool ok?
When did I get hot?
I am speaking about a naked char * that points to the
start of a sequence o bytes that should end with a
terminating zero.
It is NOT part of the representation of a string any more than a pointer
to a double is part of the representation of a double.
By definition of the data structure, its length is
not known, and the same scan must be repeated
each time we access the length.
But, if you access it repeatedly and the length matters, there is
nothing preventing you from keeping track of its length. Far too often,
the length doesn't matter and then, it would be wasteful to keep track of
it, nevertheless. Especially in a relatively low level language
More serious, the failure modes are quite horrible.
No failure mode exists for correctly written code.
In writing mode a wild pointer is like a loaded
machine gun, ready to start shooting around
at random. Pieces of the program, essential data
like the return address are wiped by the gun,
without any way for the system to stop it.
Which has zilch to do with strings and everything with the fact that C
supports pointers the way it does. And C pointers are largely responsible
for C's strength and popularity.
The program is in an undeterminable state,
depending on the direction the machine gun was
shooting.
Again, nothing to do with C strings.
Ahh. How nice. We are fearful. We risk that but
it works you see?
Have I ever told you that C is a sharp tool?
*I* do not do any mistake, you say.
Nope, I didn't say *anything* like that. Please have the minimal decency
to quote me correctly.
Well Dan, just keep cool.
You'd better take your own advice.
I have no fear to recognize that I do make mistakes.
Neither do I.
You say:
Well, Microsoft proposed one recently. And there are several.
I can't tell you which are "popular" since I am not doing
that kind of research. But they are surely used.
^^^^^^^^^^^^^^^^^^^^^^^^
Where does this certainty come from, since you haven't done any research
in this direction?
Safety was one of the more widespread goals.
C strings are perfectly safe.
I am trying to
build checked strings into lcc-win32. I think that a more
debuggable environment is easier to work with.
What happens when the incompetent programmer modifies the bytes containing
the strings length, by misusing pointers?
Nothing is safe in the hands of the incompetent.
The language doesn't support it.
So, they're not implemented in C?
I repeat that length prefixed strings should be easy to
use: name[2] should do what is supposed to.
Null terminated C *are* easy to use. And both can be misused.
My whole point is that data structure development should
be opened up to the C user that should be able to
specify data types that follow special rules he/she defines.
Isn't this already the case? Aren't users allowed to define they own
data structures?
For instance you could add a "flags" field to the standard
length prefixed string, and implement read only
strings, or time stamp based data, or whatever.
Precisely. It's the user job to do anything it wants.
The language should allow people defining programs
that handle the data structures in a way it suits them the
best.
It has being doing exactly this for the last 30 years. Have you been
sleeping?
C is not object oriented but we all use lists, stacks, hash tables
in our everyday programming.
So what?
No, this is a human performance issue. People get bored of
details. Computers do not.
So, people develop libraries tuned to their *specific* needs.
People use computers to make repetitive work. Why can't
we use the computer to check for mistakes?
Because C pointers allow mistakes that can't be mechanically detected.
Because it is perfectly possible to make mistakes even in languages that
allow all the checking you're dreaming about.
Your answer is:
Your are competent Dan. Surely more than me.
I belong to the other ones.
The ones that make mistakes. I am not afraid of saying this,
maybe because I think knowing this is the start of
knowledge.
Competent programmers make mistakes, too. Only perfect programmers don't.
However, it is a big difference between the mistakes made by competent
programmers and those made by incompetents.
When you realize your mistakes you can start learning.
Only then.
You start learning before that, but you also learn A LOT from your own
mistakes. But this has exactly zilch to do with a discussion about
counted strings...
Of course not Dan. Sure. I believe you that 100%
Believe me or not, this is one kind of mistake I am perfectly capable of
avoiding.
The garbage collector. I wrote one for my Lisp interpreter
in the 90ties, and I have adapted Mt Boehm's work to lcc-win32.
The GC is much better than malloc/free. But I know, that's
another discussion ...
AFAIK, Boehm's GC is not a complete solution and I am not aware of any
complete solution for C. The run time costs would exceed by far the
costs of malloc and friends.
I want it to be sharper Dan. C is not sharp enough
with all those bugs that creep the programs.
The bugs are not C's problem. Show me one language where the incompetent
is guaranteed to write bug free code.
You can't be sure of a tool if it is not designed to be sharp and safe.
Which part of C's design is unsafe?
You take the knife not at the edge?
That's precisely the point. The safety of both C and the knife is
dictated by the way they are used. Both are safe when correctly used
and unsafe when misused.
A knife is a sharp tool by its very nature.
But it can only be used because
you do not touch at the edge isn't it?
And what is your point?
That blunt side, that provides safety for your hand
makes for a usable knife. Without it, using a knife
is cutting yourself in the fingers
I found C's safety features perfectly adequate. Any additional safety
feature that affects its sharpness is not going to be accepted by the
competent C programmers.
A couple of weeks ago, bound checked pointers were a start. Have you
already finished that project? I'd like to play with your compiler that
implements bound checked pointers.
A better string library would be an achievement.
You have completely failed to convince anyone that your idea of a string
library would be any better than the <string.h> stuff.
And, since N such "better" string libraries have already been implemented,
why bother with a new one? Just because all the others were not written
by you? (i.e. the NIH - not invented here - syndrome)
Nothing spectacular, and very simple.
Is there anyone preventing you from doing the job? Hopefully, after
finishing the bound checked pointers...
BTW, what's the point in asking our opinions, if you're completely deaf to
them? Wouldn't your time be better spent working on your ideas, rather
than pointlessly arguing about them?
Dan