shdocvw: Use array syntax with array elements (Try 2)
Andrew Talbot
Andrew.Talbot at talbotville.com
Sat May 10 08:27:25 CDT 2008
Jacek Caban wrote:
> Why? Both syntaxes are correct, so it's a matter of style preferences. I
> prefer the style I use and I don't see any reason to change it.
>
> Jacek
Speaking generally, there is one potential opportunity to create a
hard-to-find bug. If one has something like, say:
struct tagS { int i; };
...
struct tagS ar[N];
then it is possible for a programmer to subconsciously believe he or she is
accessing the nth element of the array, but to accidentally write
ar->i = 3;
instead of
(ar + n)->i = 3;
This would compile and run fine, but would write to the zero'th element
instead of the nth.
Whereas, if one adopts the array style
ar[n].i = 3;
then it is impossible to have this accident, since the following is
syntactically incorrect.
ar.i = 3; /* error: request for member ?i? in something
/* not a structure or union
I suspect I am likely to be a bit irritating, from time to time, in
reporting static issues. But if I find that a genre of report gets
rejected - say, for example, that nobody cares if an enum list ends in a
trailing comma - then I shall just switch off that check. Hopefully, it is
better to be bothered 100 times by me than 100,000 times by a static
analyzer. :)
--
Andy.
More information about the wine-devel
mailing list