I think the message here is that macros are there to help us, but they won’t
if they embed source code in an arbitrary and confusing way. This example
obscures meaning because the macro is supposed to help with one particular
array (named array) that has not even been declared when the macro is
defined. It doesn’t really mean anything to the reader when first
encountered and is not in any way general.
A more useful macro would be for example
#define ARRAY_LENGTH(anyarray) ((int)(sizeof(anyarray) /
sizeof(anyarray[0])))
then the line
for(d=-1;d <= ARRAY_LENGTH(array)-2;d++)
should both work and be clearish, though it’d be even better if rearranged
so the iterator could start at 0.
Also ARRAY_SIZE is reusable for any array.
I know this is expanding on a not very relevant theme but we’ve all got to
learn so if this helps, great. Now my target machine has rebooted I’ll get
back to work…
BTW anyone who really wants to see how to write good C code should browse
http://www.ioccc.org/main.html
----- Original Message -----
From: Gunko Andrey
To: Windows System Software Devs Interest List
Sent: Wednesday, December 13, 2006 1:58 PM
Subject: RE: [ntdev] confused
I agree that in general using of such macro is the right thing to do. But in
case of his code it haven’t any sense. It only makes a signed/unsigned
mistake.
Andrey Gunko
soft Xpansion Ukraine Ltd.
Programmer
Powered by eKnow-how
Artjoma St. 118B … 83048 Donetsk … Tel/Fax: +38 062 3818874 …
Internet: [www.soft-xpansion.com]
|-----Original Message-----
|From: xxxxx@lists.osr.com [mailto:bounce-272761-
|xxxxx@lists.osr.com] On Behalf Of Don Burn
|Sent: Wednesday, December 13, 2006 3:45 PM
|To: Windows System Software Devs Interest List
|Subject: Re:[ntdev] confused
|
|
|“Gunko Andrey” wrote in message news:xxxxx@ntdev…
|>I think the problem in TOTAL_ELEMENTS. If you use the array of constants
|>why
|> don’t you use array of constant size - int array[7]…?
|
|Actually, using TOTAL_ELEMENTS is the right thing to do, since it means the
|array size can be changed without worrying about changing 7 or some #define
|to keep the walk the same. I know a lot of professional shops that require
|coding like this since it removes bugs.
|
|
|–
|Don Burn (MVP, Windows DDK)
|Windows 2k/XP/2k3 Filesystem and Driver Consulting
|http://www.windrvr.com
|Remove StopSpam from the email to reply
|
|
|
|
|—
|Questions? First check the Kernel Driver FAQ at
|http://www.osronline.com/article.cfm?id=256
|
|To unsubscribe, visit the List Server section of OSR Online at
|http://www.osronline.com/page.cfm?name=ListServer
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer