[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (main_buf = *main_buf_p) is not syntacticly like (i = *j) ?
- To: Shachar Shemesh <linuxil(at-nospam)consumer.org.il>
- Subject: Re: (main_buf = *main_buf_p) is not syntacticly like (i = *j) ?
- From: "Nadav Har'El" <nyh(at-nospam)math.technion.ac.il>
- Date: Mon, 2 Jul 2001 16:06:47 +0300
- Cc: Shaul Karl <shaulka(at-nospam)bezeqint.net>, linux-il(at-nospam)linux.org.il
- Delivered-To: linux.org.il-linux-il@linux.org.il
- Hebrew-Date: 11 Tammuz 5761
- In-Reply-To: <3B407A6D.7050601@consumer.org.il>; from linuxil@consumer.org.il on Mon, Jul 02, 2001 at 03:43:09PM +0200
- References: <E15H2NP-0002sn-00@rakefet> <20010702153224.A191@leeor.math.technion.ac.il> <3B407A6D.7050601@consumer.org.il>
- Sender: linux-il-bounce(at-nospam)cs.huji.ac.il
- User-Agent: Mutt/1.2i
On Mon, Jul 02, 2001, Shachar Shemesh wrote about "Re: (main_buf = *main_buf_p) is not syntacticly like (i = *j) ?":
> Nadav Har'El wrote:
>
> >Which means the jmp_buf type is an array. In C you can't normally assign
> >arrays like you did (because C thinks you're trying to assign pointers, rather
> >than the content of the array), so either do
> >
>
> Slight correction. I know I lost a bet over this, and I know many people
> make this mistake.
>
> The compiler doesn't view arrays as pointers. Arrays and pointers are
> distinct things in C. They are easily castable one into the other, hence
> the common misconception, but they are defenitely distinct.
I know very well the difference between arrays and pointers in C, and I
don't think I said anything wrong. Take a look at Dennis Ritchie's "The
Development of the C Language" for how the confusion of pointers and arrays
came about, and why it's a feature, not a bug :)
It's in http://cm.bell-labs.com/cm/cs/who/dmr/chist.html or
http://cm.bell-labs.com/cm/cs/who/dmr/chist.pdf.
Anyway, I wasn't saying that these were pointers. In fact, if they were,
they were assignable, and the whole thing would work. But I meant was:
When C sees an array on the right hand of an assignment, it treats it as a
pointer, which is why you can do something like
char *p, s[7];
p=s;
But when it sees an array on the left hand side of the assignment (like the
original poster used), it barfs. It should complain that the left-hand side
of the assignment is not assignable (in compiler-speak, not an lvalue),
and indeed Solaris's compiler says:
"z.c", line 8: left operand must be modifiable lvalue: op "="
But gcc's compiler prints the much less clear "incompatible types in
assignment". It might be because it first converts the right-hand-side
to a pointer, but of course cannot do the same for the left-hand-side of
the assignment, and then sees it cannot assign a pointer to an array.
--
Nadav Har'El | Monday, Jul 2 2001, 11 Tammuz 5761
nyh@math.technion.ac.il |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Hospitality: Making your guests feel at
http://nadav.harel.org.il |home, even if you wish they were.
=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il