lkml.org 
[lkml]   [2004]   [Feb]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: &array considered harmful?
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:01    [W:0.139 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site