K
Keith Thompson
jacob navia said:Keith Thompson a écrit :Are you suggesting that the C standard should be changed so that
strings are no longer terminated by '\0'?
Yes. If we have the length as a size_t we do not need to start
scanning memory at each access to get the length of the string, what
is GREATLY inefficient and has been pointed out as inefficient since
decades!!!!!
There are dozens of
standard library functions that use this representation, and it's
central to the semantics of string literals.
lcc-win32 proposed replacing
strcmp --> Strcmp
strcat --> Strcat
where the arguments are the same but in THOSE kind of strings.
Similarly, the compiler when it sees:
String s = "This is a string";
would make an array of characters and prepend the length instead of
adding a terminating zero.
Conceivably you could add a new string representation *in addition to*
the existing one.
Yes.
You would then be permanently stuck with two
distinct and incompatible ways of representing strings. (Breaking
nearly all existing code is not an option.)
Yes, new code would use Strcmp, old would use strcmp.
I have tried porting code that uses heavily strings in the old
representation to the new one and it is relatively easy to do.
Of course, it's easy enough to implement this kind of thing in a
library using purely standard C; perhaps that's why there isn't much
enthusiasm for adding it to the language.
No. The problem is that you want to keep:
String s;
...
s[23] = 'b';
and not forcing people to use:
strindex(s,23)
strindexassign(s,23,'c');
or similar nonsense.
I don't recall every saying I "want to keep" any such thing.
C does not currently support operator overloading. Your String type
could be implemented in standard C, but it would require using
additional function calls. In a hypothetical C-like language that
*does* support operator overloading, a new String type could be
implemented more conveniently.
I do not necessarily oppose either adding operator overloading to a
future C standard, or implementing it as an extension in an existing C
compiler. I've used languages that support operator overloading, and
I've found it very convenient at times. (It's also prone to abuse.)
On the other hand, operator overloading is really nothing more than
syntactic sugar; there's nothing you can do with it that you can't do
without it (though perhaps much more verbosely).
A string library implemented in standard C would be a good topic for
discussion in this newsgroup. A string library that depends on
extensions provided by a single compiler would be a good topic for a
newsgroup that deals with that copmiler. Advocacy of changes to the C
language belongs in comp.std.c. You've complained that your
suggestions haven't been well received there; that doesn't seem to
have stopped you from talking about them here.
Get this through your head. I do not oppose your ideas. Some of them
are undoubtedly worth considering. I am sick and tired of your
attitude and your insistence on discussing them in a form where they
are off-topic.
Basically it implements all functions of the C library using the new
Strings. The syntax is almost the same:
Strcmp --> strcmp
Strcat --> Strcat
etc
Using operator overloading operators like
if (! s) {
}
have their usual meanings.
I asked for a pointer to the documentation. Is there any? If not,
it's not worth my time to consider it.
[...]
Maybe. I would not say that it is wrong. But the insistence for using
gcc with the -pedantic etc options that is getting recommended here
goes with the attitude of negating C99 in this bgroup.
Have you tried "gcc -pedantic -std=c99"? I use it routinely.
I remember the
discussion about the FAQ we had, where I was flamed because I insisted
on upgrading the FAQ to C99.
I don't remember that.
[...]
I am not imposing anything to anyone. I have explained with a lot of
arguments why I am doing this or that. Nobody is forced to use
lcc-win32 but I think that arguing and convincing people still is
possible, and is still the oenly way to publish your own ideas.
You are imposing extensions that are specific to lcc-win32 on this
newsgroup. You are imposing your advocacy of changes to the standard
on a newsgroup that discusses the language *as it currently exists*,
after being told repeatedly that such discussions would be more
appropriate in comp.std.c.