On Friday, June 01, 2012 12:39:48 pm Eitan Adler wrote: > On 1 June 2012 07:24, John Baldwin <j...@freebsd.org> wrote: > > This is why I personally loathe assignment side effects in boolean > > expressions > > for control flow. I tend to write this sort of thing instead as: > > > > channel->dtr_arr[dtr_index].dtr = dtrh; > > if (dtrh != NULL) { > > Same here. I was told to use the assignment is style(9) by multiple > people though. If it really is, I wish it would change.
style(9) doesn't make a clear statement either way, but it has contradicting examples. First: while ((ch = getopt(argc, argv, "abNn:")) != -1) (and this one I use all the time myself as that is the common idiom for getopt()) Second: error = function(a1, a2); if (error != 0) exit(error); Also, style(9) tends to frown on assignments that are side-effects in other places, for example: Be careful to not obfuscate the code by initializing variables in the declarations. Use this feature only thoughtfully. DO NOT use function calls in initializers. struct foo one, *two; double three; int *four, five; char *six, seven, eight, nine, ten, eleven, twelve; four = myfunction(); Some newer changes added at the end do use assignment side-effects while demonstrating other rules (the !p example and err(3) and warn(3) examples, this last I find particularly obfuscated and painful to read). Note that I do not consider this to be an assignment side effect: if (ioctl(...) < 0) err(1, "ioctl"); That is, I don't write that out as: i = ioctl(...); if (i < 0) However, I do split it out if the return value is used for more than error checking, e.g.: fd = open(...); if (fd < 0) err(1, "open"); -- John Baldwin _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"