On Wed 2008-10-15 13:53:22 UTC-0400, Bill Cunningham ([EMAIL PROTECTED]) wrote:

> > memset(s, '\0', sizeof s);
> 
>     memset(s,'\0',sizeof(s));
> 
> ;-)

The parentheses are superfluous.  You only need them if s is a
datatype.  In most cases where you use sizeof, you're using it to find
the width of a variable, not a datatype.

Unfortunately code like this is still quite common:

short ara[10];
memset(ara, 42, sizeof(short));

But what happens if we change ara's datatype, but forget to fix the
code properly?

long ara[10];
memset(ara, 42, sizeof(short));

So we should use this instead:

long ara[10];
memset(ara, 42, sizeof ara);

Regards
Andrew

Reply via email to