Nested Comments in C -- A recent experience
Dave Jones
djones at megatest.UUCP
Sat Mar 17 08:58:05 AEST 1990
>From article <2381 at dataio.Data-IO.COM>, by bright at Data-IO.COM (Walter Bright):
> In article <9130008 at hpavla.AVO.HP.COM> gary at hpavla.AVO.HP.COM (Gary Jackoway) writes:
> << (void) memcpy(/*targ*/ (void *) &x, /*src*/ (void *) &y, sizeof(y));
> <Wouldn't
> <// target: source:
> < (void) memcpy((void *) &x, (void *) &y, sizeof(y));
> <be more readable? Or maybe:
> </* Copy y into x */
> < (void) memcpy((void *) &x, (void *) &y, sizeof(y));
>
> It's more readable if you eliminate the redundant clutter:
> memcpy(&x,&y,sizeof(y)); /* Copy y into x */
Strictly speaking, you have to keep the (void*) casts, just in case some
enemy system codes some kinds of pointers in screwy ways. It can happen.
So we got this:
memcpy((void*)&x,(void*)&y,sizeof(y)); /* Copy y into x */
Not too bad.
If I had my way, the C++ style out-to-the-end-of-the-line comment would
be the only kind available.
// Know what I mean, Bean?
But then, if I had my way, I wouldn't be programming now would I? I would
have WAY to much money to bother with work.
As it is, I use only two styles:
/*
* Block comments
* that can go on and on...
*/
... and ...
/* ... out to end of line comments. */
The reason I don't do blocks ...
/* ... like a bunch */
/* of out to end */
/* of line comments... */
... is that blocks like that are too hard to edit, especially if you
like to ...
/* ... line up the */
/* comment-ends */
/* nice and tidy. */
Rarely, I do want to put comments on actual parameters, as in the
original memcpy example. I still use the o-t-e-o-l comment:
memcpy( (void*)&y, /* target */
(void*)&x, /* source */
sizeof(y)
);
I guess KR indentation purists would do this:
memcpy(
(void*)&y, /* target */
(void*)&x, /* source */
sizeof(y)
);
Nah, maybe not.
One of the most affected comment styles that I have seen inflicted on the
innocent code-reading public had all the comments on the left! Made me
just want to take the guy and shake him.
/* It all looked */ main(argv, argc)
/* really weird, */ char** argv;
/* even pompous, */ {
/* you know what */ printf("Goodbye, cruel world.\n");
/* I mean, Bean? */ }
More information about the Comp.lang.c
mailing list