httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Stein <gst...@lyra.org>
Subject sizeof stylistic convention (was: cvs commit: ... mod_cgi.c mod_include.c)
Date Tue, 16 May 2000 20:50:50 GMT
On 16 May 2000 stoddard@locus.apache.org wrote:
>...
>   --- mod_include.c	2000/05/16 01:59:07	1.28
>   +++ mod_include.c	2000/05/16 20:19:29	1.29
>   @@ -1129,7 +1129,7 @@
>    
>            if (rr->status == HTTP_OK && rr->finfo.protection != 0) {
>                memcpy((char *) finfo, (const char *) &rr->finfo,
>   -                   sizeof(struct stat));
>   +                   sizeof(rr->finfo));
>                ap_destroy_sub_req(rr);
>                return 0;
>            }

This is a stylistic convention that I'd like to call attention to. When
doing a sizeof(), it is "best" to do a sizeof of the target variable or
expression, rather than hard-coding a type. When the type changes, then
the sizeof doesn't need to be maintained.

Some examples:

  p = malloc(sizeof(*p));      // be careful; don't write sizeof(p) ! :-)
  memcpy(p1, p2, sizeof(p1));  // or sizeof(p2)


Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/


Mime
View raw message