[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sv: Sv: Sv: Sv: PenguinFile



Bjarke Hammersholt Roune wrote:

>>> char* pThisIsAString = "whatever";
>>> WriteToDisk(pThisIsAString);
>>> WriteToDisk(pThisIsaString);
>>>
>>> Should this compile? I would consider it a bug if it did...
>>>
>>Why shouldn´t it? pThisIsAString is a completely valid C-style string.
>>And, depending on the implementation, you eventually *can* modify it.
>>
>Actually there are two bugs on those two lines. pThisIsAString is an unconst
>pointer, but "whatever" yields a const pointer. In the third line,

Bjarne Stroustrup, "The C++ Programming Language, 3rd Ed.", Section 5.2.2:

"A string literal can be assigned to a char*. This is allowed because in
previous definitions of C and C++. the type of a string literal was char*.
Allowing the assignment of a string literal to a char* ensures that
millions of lines of C and C++ remain valid. Ti is, however, an error to
try to modify a string literal through such a pointer: 
[...]"

>pThisIsAString is spelled with the wrong case for the a.

Emails always contain typos.

>>>>Byte order. if you have some integer, say 123456789 (hex 75BCD15),
>
>>>>
>>> Sometimes you REALLY wonder why people couldn't just have agreed on this
>>> from the start, don't you? I mean, something as stupid as this DOESN'T
>>>
>>Well, which one would you have chosen? They are completely equal...
>>
>I would have chosen whatever everybody else used.

Bad luck. Back then there were some teams independently designing CPUs at
the same time - so there wasn't "everybody else".


	Christian
--

Drive A: not responding...Formatting C: instead