Coding style updates

Gerald (Jerry) Carter jerry at samba.org
Sun Oct 21 13:23:15 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Metze,

> here're are some updates to the README.Coding,
> please review and comment.
> 
> metze
> 
>


- -If the beginning statement has to be broken across lines due to length,
- -the beginning brace should be on a line of its own.
- -

- -1 on this.  Michael has already commented as well.

+	for (very_long_var_name_x=1;
+	     very_long_var_name_x<10;
+	     very_long_var_name_x++) {
 		print("%d\n", x);
 	}

Please fix this line.  Should be:

+	for (very_long_var_name_x=1;
+	     very_long_var_name_x<10;
+	     very_long_var_name_x++)
 	{
 		print("%d\n", x);
 	}

+
+These should only be use together with return, goto, exit() or free():
+
+	if (x == 1) return 0;
+
+	if (some_long_function_name_check(x))
+		goto failed;
+
+	if (ptr) free(ptr);
+

- -1.  *Always* use braces and none of the if () ...; on
one line.  That's awful.



- -	if ((x = malloc(sizeof(short)*10)) == NULL ) {
+	x = malloc(sizeof(short)*10);
+	if (!x) {
 		fprintf(stderr, "Unable to alloc memory!\n");
 	}

 or

- -	x = malloc(sizeof(short)*10);
- -	if (!x) {
+	if ((x = malloc(sizeof(short)*10)) == NULL) {
 		fprintf(stderr, "Unable to alloc memory!\n");
 	}

- -1.  We had this discussion before as well.  Mainly I don't
like the "this one *or* that one".  Pick one.  We previously
decided on if ((x=malloc) == NULL) format.





jerry
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHG1LDIR7qMdg1EfYRAkXoAJ9h8gKFf8hoYAB7pLAaVwZ+LX0YDACfZoLF
cdTfW62EiceaGI0o/2b7vN8=
=CfgG
-----END PGP SIGNATURE-----


More information about the samba-technical mailing list