comment style

Dave P. Schaumann dave at cs.arizona.edu
Sun Jan 6 09:43:43 AEST 1991


In article <1991Jan04.164355.15674 at sco.COM> ron at scocan.sco.COM (Ron Irvine) writes:
!A need for // (real) comments:
!
!
!#include <stdio.h!
!void main() {
!	int *p;
!	int a;
!	int f = 10;
!	int n = 5;
!
!	p = &f;
!
!	a = 100/*p	/* calculate first factor */
!	    + 25/n;	/* and second factor */
!
!	printf("The answer is %d, %s\n", a, (a==15)?"OK":"BAD");
!}
!
!
!The actual program that contained this problem was very complex.
!It took two of us a day to figure out what had happened.
!
! [ flame about compilers missing /* within comment deleted ]

The failure, IMHO, is in the compiler for not testing for the sequence /*
within the comment.  I think this should be a required feature of every ansi
c compiler.  Note that if you are using gcc, -Wall will notify you of this.

!The // comment style should have been adopted by the ANSI committee
!if for no other reason that to reduce the likelihood of a programmer
!falling into this horrendous trap. If // style comments had been
!used in the above program the compile would have failed.

Only if /* */ style comments were not used.  Personally, I have no great love
for /* */ comments, but I see no compelling reason to have //, and have heard
no argument for // that doesn't boil down to 'I like it that way better'.

!Ron Irvine, ron at sco.com

Dave Schaumann		| You are in a twisty maze of little
dave at cs.arizona.edu	| C statements, all different.



More information about the Comp.std.c mailing list