Re: &array considered harmful?
From: Mitchell Blank Jr
Date: Mon Feb 23 2004 - 17:54:40 EST
Robert T. Johnson wrote:
> memset(&A, 0, sizeof(A));
[...]
> This works because in C, for a local array, &A == A. The problem is
> that this is very brittle.
I'm probably in the minority here, but I've gotten into the habit of saying
"&A[0]" since I think it's more explicit ("I want the address of the
FIRST ELEMENT of the array") and it avoids exactly the problems you mention.
It's true that it's equivelent to just saying "A" (well, almost - if "A"
is a pointer then it could be an lvalue while "&A[0]" never is) but I
like the visual cue of that "&" provides. Matter of taste I guess -
I'm sure some people consider it ugly.
-Mitch
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/