Hi!

24-Май-2004 20:16 [EMAIL PROTECTED] (tom ehlert) wrote to "Arkady V.Belousov"
<[EMAIL PROTECTED]>:

>>-#define LENGTH(x) (sizeof(x)/sizeof(x[0]))
>>+#define LENGTH(x) (sizeof (x)/sizeof *(x))
te> (sizeof(x)/sizeof(x[0])) has worked for me for ~20 years now.
te> could you please explain why this should be fixed (other then your fun
te> to change everything)

     Well, there are a lot of possibilities, which you can't predict. For
example:

#define f(v) (type)(v)

Looks safe? But try it in: "f(v)[0]" and you under trouble, especially if
both `type' is a pointer type and `v' is a pointer.

     In above case at first glance I don't see possibilities to break
integrity ([] have top most priority over other operations), but this not
mean, that such case can't be constructed by some smart man, which knows
language even better.

PS: For some peoples macros min()/max() also may "work for ~20 years", but
this doesn't mean that these macros are "unbreakable", this just mean, that
there wasn't used arguments with side effects.




-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id149&alloc_id│66&op=click
_______________________________________________
Freedos-kernel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freedos-kernel

Reply via email to