J
James Kuyper
Rick said:On Wednesday, January 22, 2014 9:08:04 PM UTC-5, Seebs wrote:
Example:
char* list[] = { "one", "two", "three" };
In this case, list[0] should contain a writable character array of four bytes,
lines[1] likewise, and list[2] should be six bytes.
How can it when list is an array pointers?
The pointers should point to read-write values.
Note that there is a big difference between "contain" and "point at".
....
They are not implemented on all C compilers.
It is supported on all fully conforming implementations of C99, which
has been the current version of the C standard for nearly 15 years now.
....
I did not know that. It's why I use a C++ compiler to compile my C code.
It has many syntax allowances C does not.
It also disallows many kinds of syntax that C supports. This is a pretty
normal case when you're talking about two different languages. There's
nothing wrong with compiling code using C++; but when you do so, you
should discuss the consequences in comp.lang.c++, not comp.lang.c. Doing
so will avoid lots of confusion, both on yours and other peoples'.
union {
char* p;
int _p;
};
Yeah, but not really. It's only a violation of C++'s protocol for pointer
exchange. ...
The proper term is "type conversion", not "pointer exchange". The rules
of both C and C++ allow an int* to have a different size,
representation, and alignment requirement from that of void*, and that
that was done precisely because there have been real machines where that
was actually the case. Therefore, type conversion can be something
considerably more complicated than just moving something from one
register to another, as is implied by your use of "exchange".
... As far as the machine goes, it's a pointer and they can be
exchanged. In my opinion, the compiler should allow it, and only warn
about it.
Well, the people who designed C++ disagree with you about that; they
think that type safety is very important; so important as to justify
treating it as an error when such a type conversion is not explicitly
requested. This is one case where the C rules are more in alignment with
your opinions: C worries less about type safety than C++, and therefore
allows the conversion of void* to other pointer types to occur implicitly.