Velocity Reviews > Assigning an array to another array using C's assignment operator

# Assigning an array to another array using C's assignment operator

James Dow Allen
Guest
Posts: n/a

 02-25-2013
On Feb 1, 7:56*am, "BartC" <(E-Mail Removed)> wrote:
> "glen herrmannsfeldt" <(E-Mail Removed)> wrote in message
> > * *A=B+C;
> > Seems to me that you could almost do that in C, as there is no
> > current operation defined for + between two arrays (or pointers).

>
> No, because arrays aren't handled by value as they would need to be.
>
> Besides, the "-" operator *is* defined between two arrays (although exactly
> how the arrays are related is significant):
> ...
> and it wouldn't really fit in well with an A+B that worked completely
> differently.

Hear, hear!

Let's have a show of hands. How many think it would be
a delightful increase of expressive power to define "+"
for arrays? How many agree the inconsistency between
"+" and "-" would make you want to barf?

I'll start. My vote is for ... Barf.

In that language,
"69" - 2 // is equal to 67
"69" + 2 // is equal to "692"

"Powerful" languages are already available for those
who like such "powerful" features.
It seems malicious to try to inflict them on C.

James

glen herrmannsfeldt
Guest
Posts: n/a

 02-25-2013
James Dow Allen <(E-Mail Removed)> wrote:

(snip)

> Javascript already does something barfy^H^H^H^Hwonderful.
> In that language,
> "69" - 2 // is equal to 67
> "69" + 2 // is equal to "692"

PL/I, at least, does it consistenty"

'69'-2 is 67,
'69'+2 is 71

You have to:

'69' || 2
if you want '692'.
(and you might actually get '69 2' because it blank pads
the conversion.)

> "Powerful" languages are already available for those
> who like such "powerful" features.
> It seems malicious to try to inflict them on C.

Could add some completely new operators for array expressions.

-- glen

Anand Hariharan
Guest
Posts: n/a

 02-26-2013
On Jan 31, 6:56*pm, "BartC" <(E-Mail Removed)> wrote:
> "glen herrmannsfeldt" <(E-Mail Removed)> wrote in message
>
> news:kef22i\$sr8\$(E-Mail Removed)...
>
> > * *A=B+C;
> > Seems to me that you could almost do that in C, as there is no
> > current operation defined for + between two arrays (or pointers).

>
> No, because arrays aren't handled by value as they would need to be.
>

Correct.

> Besides, the "-" operator *is* defined between two arrays (although exactly
> how the arrays are related is significant):
>

IANAL, but that is incorrect. The operands of the minus operator are
the decayed pointer values, not the arrays.

> #define n 10
> int A[n],B[n];
> int C;
>
> C=A-B;
>
> printf("%d\n",C);
>

Again, IANAL, but that is UB. (Your compiler might probably warn you
about C being the wrong type, that it should be ptrdiff_t, but that is
not a constraint violation.)

- Anand

Anand Hariharan
Guest
Posts: n/a

 02-26-2013
On Feb 26, 10:27*am, Anand Hariharan
<(E-Mail Removed)> wrote:
> On Jan 31, 6:56*pm, "BartC" <(E-Mail Removed)> wrote:
>
> > "glen herrmannsfeldt" <(E-Mail Removed)> wrote in message

>
> >news:kef22i\$sr8\$(E-Mail Removed)...

>
> > > * *A=B+C;
> > > Seems to me that you could almost do that in C, as there is no
> > > current operation defined for + between two arrays (or pointers).

>
> > No, because arrays aren't handled by value as they would need to be.

>
> Correct.
>
> > Besides, the "-" operator *is* defined between two arrays (although exactly
> > how the arrays are related is significant):

>
> IANAL, but that is incorrect. *The operands of the minus operator are
> the decayed pointer values, not the arrays.
>
> > #define n 10
> > int A[n],B[n];
> > int C;

>
> > C=A-B;

>
> > printf("%d\n",C);

>
> Again, IANAL, but that is UB. *(Your compiler might probably warn you
> about C being the wrong type, that it should be ptrdiff_t, but that is
> not a constraint violation.)
>
> - Anand

'<512aa3c0\$0\$1992\$(E-Mail Removed)>'.

- Anand