Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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" <b...@freeuk.com> wrote:
> "glen herrmannsfeldt" <g...@ugcs.caltech.edu> 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.

Javascript already does something barfy^H^H^H^Hwonderful.
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
 
Reply With Quote
 
 
 
 
glen herrmannsfeldt
Guest
Posts: n/a
 
      02-25-2013
James Dow Allen <> 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
 
Reply With Quote
 
 
 
 
Anand Hariharan
Guest
Posts: n/a
 
      02-26-2013
On Jan 31, 6:56*pm, "BartC" <b...@freeuk.com> wrote:
> "glen herrmannsfeldt" <g...@ugcs.caltech.edu> wrote in message
>
> news:kef22i$sr8$...
>
> > * *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

 
Reply With Quote
 
Anand Hariharan
Guest
Posts: n/a
 
      02-26-2013
On Feb 26, 10:27*am, Anand Hariharan
<mailto.anand.hariha...@gmail.com> wrote:
> On Jan 31, 6:56*pm, "BartC" <b...@freeuk.com> wrote:
>
> > "glen herrmannsfeldt" <g...@ugcs.caltech.edu> wrote in message

>
> >news:kef22i$sr8$...

>
> > > * *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



Sorry, didn't notice that 'Noob' had already addressed this in
'<512aa3c0$0$1992$>'.

- Anand
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning an array to another array using C's assignment operator Myth__Buster C Programming 1 02-01-2013 12:27 AM
Assigning an array to another array using C's assignment operator Myth__Buster C Programming 0 02-01-2013 12:25 AM
Assigning an array to another array using C's assignment operator Myth__Buster C Programming 0 02-01-2013 12:05 AM
Assignment operator self-assignment check Chris C++ 34 09-26-2006 04:26 AM
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM



Advertisments