Path: csiph.com!news.mixmin.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: C++ comma operator ?
Date: Mon, 03 Oct 2022 02:38:57 -0700
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <86pmf9i6vi.fsf@linuxsc.com>
References: <871qrsmyyl.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader01.eternal-september.org; posting-host="dc7783cc82a171774bfb92363bafa541"; logging-data="2247630"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/62+k2vMpZvDR4zVfGStcte/vjtbAao1M="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:O/oDonlXnyfjGWLcyVGQ2BED0D4= sha1:X4VT5BY328f/WsCQb+phsHDP/Wc=
Xref: csiph.com comp.lang.c++:86780
Keith Thompson writes:
> Lynn McGuire writes:
>
>> Is this C++ statement using the comma operator ?
>>
>> write(6, "(3(1x,i3),1x,f12.6,1x,f12.6)"),
>> hkl(1, i), hkl(2, i), hkl(3, i), f_calc(1, i), f_calc(2, i);
>
> Yes, five of them, easily seen by reformatting the code:
>
> write(6, "(3(1x,i3),1x,f12.6,1x,f12.6)"),
> hkl(1, i),
> hkl(2, i),
> hkl(3, i),
> f_calc(1, i),
> f_calc(2, i);
>
> Assuming there's no macro funny business going on, that's 6
> function calls (or macro invocations?) separated by comma
> operators. (The commas separating function arguments are of
> course not comma operators.)
>
> Replacing the comma at the end of each line by a semicolon (and
> possibly surrounding the whole thing with curly braces) yields
> equivalent code.
In C++ that rule does not hold, because of the possibility of an
overloaded operator,(). Indeed in this case it appears that
there is an operator,() overload, and that is what makes this
statement work; changing the statement to be a series of
semicolon-terminated statements wouldn't work at all.