Re: never heard anything like it in my life?
From: Howard (alicebt_at_hotmail.com)
Date: 01/22/04
- Next message: red floyd: "Re: Compiling with g++ 3.0"
- Previous message: Jerry Coffin: "Re: Opening directories"
- In reply to: Jumbo: "Re: never heard anything like it in my life?"
- Next in thread: Old Wolf: "Re: never heard anything like it in my life?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Jan 2004 14:37:56 EST
"Jumbo @uko2.co.uk>" <pcr1000011<nospam> wrote in message
news:1074729603.279695@news.minx.net.uk...
> Want a laugh check out what this guy Ron Natalie said to me. pmsl:
>
> "Jumbo @uko2.co.uk>" <pcr1000011<nospam> wrote in message
> news:1074695100.709794@news.minx.net.uk...
> > Would you like a demonstration of how to assign to an array?
> > int intarr[1];
> > intarr[0] =256;
> >
> intarr[0] is NOT an array. It is an int that happens to be in an array.
> You can't assign arrays. They are the only data type in C++ that
> doesn't have assignment semantics.
>
> I don't know how to reply to this :-P
>
> AHA.
Sounds like just a difference in terminology to me. When Ron (and most
other progarmmers) talk about assigning "to an array", he means assigning to
the *entire* array, not to an individual member of an array. You obviously
talk about assigning to a member of an array using the same terminology.
It's a matter of semantics, not an argument of facts.
There is no "assignment semantic" for arrays. In other words, the
assignment operator is not defined for the array type itself, only for its
members or for pointers to arrays. You can assign values to the members of
arrays, or to pointers to array data, but not assign the array *directly*.
For example, this is illegal:
int a[3] = {1,2,3};
int b[3];
b = a; // not valid!
But of course, you *can* write
for (int i = 0; i < 3; ++i)
b[i] = a[i];
However, in the normally accepted terminology for programming, the latter is
not "assigning to an array", but rather "assigning to the members of an
array". A subtle diffrence, but it is important to be precise in this
field.
You can also write:
int* a = new int[3]; // initialize pointer with address of first element of
dynamically-allocated array data
int* b; // uninitialized pointer
b = a; // assign a to b (copying the address stored in a, not the data
pointed to by a)
But again, that is not assigning to an array, it is assigning to a pointer,
and it simply makes b and a point to the same memory location, and it is
that (unnamed) location which holds the array itself.
Many of us wish that C++ was designed so that you *could* do a direct
assignment to the entire array, as in my first example. That would have
made things a lot easier. But it's not how the C++ standard was written, so
we're stuck with it. And in order to say (in English) that such a thing
cannot be done, the only way to phrase that fact is to say "you cannot
assign to an array". (How else would you phrase it, in order to be precise
and not get your statement confused with assigning to a member of an array
or a pointer to an array, which *are* legal?)
So Ron's correct, just more careful (specific?) in his terminology than you
like to be. Give him a break, huh? He's been a great help to a lot of
people here, and he knows what he's talking about.
Regards,
Howard
(p.s., what's "pmsl" in your post mean?)
- Next message: red floyd: "Re: Compiling with g++ 3.0"
- Previous message: Jerry Coffin: "Re: Opening directories"
- In reply to: Jumbo: "Re: never heard anything like it in my life?"
- Next in thread: Old Wolf: "Re: never heard anything like it in my life?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|