Coding style updates
tridge at samba.org
tridge at samba.org
Tue Oct 23 06:31:02 GMT 2007
> > - - x = malloc(sizeof(short)*10);
> > - - if (!x) {
> > + if ((x = malloc(sizeof(short)*10)) == NULL) {
> > fprintf(stderr, "Unable to alloc memory!\n");
> > }
My preference is for separate lines, and "if (NULL == x)"
Reasoning:
1) separate lines allow you to see the result of the call in a
debugger. You can't when you use functions inside if statements.
2) putting the constant on the left, as with the (NULL == x),
catches the case where you use an = instead of a ==, so I think it
is less error prone.
Cheers, Tridge
More information about the samba-technical
mailing list