Dive Into Java?

Christophe chris.cavalaria at free.fr
Tue Oct 10 10:47:44 EDT 2006


Diez B. Roggisch a écrit :
> Christophe wrote:
> 
>> Diez B. Roggisch a écrit :
>>> The code _generated_ by the java compiler, and the C++ compiler, is not
>>> the issue here. If you as a programmer can write "a" + "b", its fine.
>>> Which is a thing to reach in C++, a bazillion of string-classes have been
>>> written....
>>>
>>>
>>> and in C++, you can do:
>>>
>>> char *a = "1";
>>> char *b = "2";
>>> char *c = a + b;
>>>
>>> But with a totally different, unexpected outcome.. I know where *I* start
>>> laughing here.
>> That code doesn't even compile. And you shouldn't be using the char*
>> compatibility strings in C++ if possible.
> 
> It was out of my head. I remember producing some wicked pointer arithmetic
> example of similar ridicule. 
> 
> And the whole argument is about java having a lot of design decisions that
> make it easier to work with is actually strengthened when you say that "you
> shouldn't use the char* ..." - because its not forbidden, and maybe someone
> else didn't follow that suggestion. I remember quite a few times calling
> the stl-string-to-char-function (no idea how that is called now)

Well, char* really is a compatibility feature in my mind. And it IS 
useful. How else would you interface C++ with existing C code and 
libraries :) That was the most probable reason you were using the STL to 
char* function.

Same for the const_cast. You shouldn't use it, but sometimes, you have 
to interface with a C api that takes a non const char* as paramter, 
despite the fact that it won't modify it in any way.



More information about the Python-list mailing list