Any limit is determined by the implementation, but the standard requires at least 15, see 5.2.4.1
The same conditions as everything else: when it is wrong, and when it is not necessary. The most famous example is that you should not specify the return value from malloc . This is pointless [*], and it may hide a random error (forgetting #include stdlib.h ). Another example is that if you randomly scatter castings between integer types, you will end up suppressing the compiler warning to narrow down or compare values ββwith and without a signature, which you should pay attention to. Throws to suppress such warnings should not be placed until you are sure that the code is correct.
[*] I used to think that there is a point, because I will write things like:
foo *p = something; ... some time later ... p = (foo*) malloc(n * sizeof(foo));
Listing provides some error protection β using the wrong type in sizeof . Visually, I see that the listing matches sizeof , and the compiler checks to see if this variable matches, so I have security.
Now I write:
p = malloc(n * sizeof(*p));
I don't need a security check because I definitely allocated the correct size memory for type p. Well, assuming multiplication is not overflowing.
Steve jessop
source share