L
lovecreatesbea...
K&R 2, sec. 5.11 says that no need to precede function and array names
with address-of operators &, why?
with address-of operators &, why?
[email protected] said:K&R 2, sec. 5.11 says that no need to precede function and array names
with address-of operators &, why?
Chris said:Presumably because they though it was worth saying, even though it's
not actually true.
Harald said:When can an alternative which does not involve the & operator not be
found? (It doesn't have to be a better alternative, just an
alternative.)
Chris said:I don't understand the question (too many `not`s, I don't know whether
to cancel or emphasise). So hoping this strikes appropriately:
* however, if you want the /address of the array/, as opposed to the
address of its first element, you have to use the & operator to
do so. (This is why I said "not actually true" above.)
Harald said:Sorry. What I meant is that I believe there is always an alternative
without the & operator, and I asked for a counterexample.
You don't. You can use a cast instead.
int main(void) {
int a[2];
int (*pa)[2] = (int (*)[2]) a;
}
And yes, & would be better, that's why I wrote the second sentence in
my previous message.
You could also have done:Harald said:Chris said:I don't understand the question (too many `not`s, I don't know whether
to cancel or emphasise). So hoping this strikes appropriately:
Sorry. What I meant is that I believe there is always an alternative
without the & operator, and I asked for a counterexample.
* however, if you want the /address of the array/, as opposed to the
address of its first element, you have to use the & operator to
do so. (This is why I said "not actually true" above.)
You don't. You can use a cast instead.
int main(void) {
int a[2];
int (*pa)[2] = (int (*)[2]) a;
}
And yes, & would be better, that's why I wrote the second sentence in
my previous message.
Nils said:You could also have done:Harald said:You don't. You can use a cast instead.
int main(void) {
int a[2];
int (*pa)[2] = (int (*)[2]) a;
}
And yes, & would be better, that's why I wrote the second sentence in
my previous message.
FILE *f = (FILE*)a;
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.