Y
ymuntyan
Then why don't you just code
char a = "";
and see what your compiler has to say about it?
I don't take it because it converts a pointer to a char for some
reason, to demonstrate some point. And it has undefined behavior
on my system I believe (I bet it's UB on your system too).
Probably because you think you know this and are just trolling.
If I am trolling, then you are double-trolling: my question was
a particular case of the original question, and your reply is
bunch of "why don't you do <something else>" like it answers
something
Here are four bytes in memory on an 8-byte boundary: 0x20414200.
Do they represent a string or part of one; four individual char; 2
short; 1 short; 2 int; 1 int; if either type of int are the
magnitude(s) large, medium, or small; 1 long; or one float? It's the
same four bytes; how could they possibly mean different things?
Indeed, this question is so hard that gcc will bite your arse if you
don't stick to "it's magic, but it's not just a byte sequence
that matters" rule, contributing to popularity of -fno-strict-aliasing
option. It has nothing to do with the original question though,
because "string" is not a data type.
Try
char x[5];
void *p1 = x; /*(1)*/
void *p2 = &x; /*(2)*/
p1 is obviously equal to p2. Since equality is transitive, how can
the right hand expression of (1) possibly be different than the right
hand expression of (2)?
So you take an array, you do the stuff. So what? What does it have to
do with a char object? Please, pointer comparison rules are not what
we are talking about (even if it was about pointers, result of
comparison with == operator is different from "being the same or
different"). Oh well.
Best regards,
Yevgen