[C-safe-secure-studygroup] Rule 12.3 review

Robert Seacord rcseacord at gmail.com
Wed Oct 4 15:29:01 UTC 2017


If you can, please put your rules analysis up on the wiki so we can find
them easily and make notes during the call.

Thanks,
rCs

On Wed, Oct 4, 2017 at 11:06 AM, Aaron Ballman <aaron at aaronballman.com>
wrote:

> On Wed, Oct 4, 2017 at 10:56 AM, Martin Sebor <msebor at gmail.com> wrote:
> > Rule 12.3 - The comma operator should not be used
> >
> > This Advisory rule prohibits the use the comma expression with
> > no exceptions.
> >
> > The stated Rationale is that it's bad for readability and that
> > the same effect can usually be achieved by other means.
> >
> > I'm not aware of any serious readability problems with the operator
> > and while I agree that the same effect can usually be achieved by
> > using other constructs, there are situations when there is no
> > alternative.  A common example is a macro that needs to expand into
> > sequenced expressions and yield a value, analogously to a function
> > call.  E.g.,
> >
> >   // log and evaluate expression X
> >   #define LOG(x)   (log (__FILE__, __LINE__, __func__, #x), (x))
> >
> > There's no comparable way to achieve the same effect.  (Wrapping
> > it in a do { } while (0) loop turns it into a statement, making
> > it unusable in contexts where an expression is required.  Using
> > an inline function is unsuitable when the expression can have
> > an arbitrary type.)
>
> In addition to that compelling example, I've seen quite a few for
> loops that use the comma operator when incrementing. e.g.,
>
> for (int i = 0, j = 0; ; ++i, ++j) /* ... */
>
> ~Aaron
>
> >
> > With that I recommend against adopting this rule.
> >
> > Martin
> >
> > _______________________________________________
> > C-safe-secure-studygroup mailing list
> > C-safe-secure-studygroup at lists.trustable.io
> > https://lists.trustable.io/cgi-bin/mailman/listinfo/c-
> safe-secure-studygroup
>
> _______________________________________________
> C-safe-secure-studygroup mailing list
> C-safe-secure-studygroup at lists.trustable.io
> https://lists.trustable.io/cgi-bin/mailman/listinfo/c-
> safe-secure-studygroup
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.trustable.io/pipermail/c-safe-secure-studygroup/attachments/20171004/912a3ea0/attachment.html>


More information about the C-safe-secure-studygroup mailing list