Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Usage of comma operator
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 26 - 36 of 36 - Expand all  -  Translate all to Translated (View all originals) < Older 
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bill Mitchell  
View profile  
 More options Sep 26 1991, 1:57 am
Newsgroups: comp.lang.c, comp.lang.c++
From: mitch...@MDI.COM (Bill Mitchell)
Date: 25 Sep 91 01:01:36 GMT
Local: Tues, Sep 24 1991 9:01 pm
Subject: Re: Usage of comma operator
In article <5...@ksr.com> j...@ksr.com (John F. Woods) writes:

>[...]

>Always code as if the guy who ends up maintaining your code will be a
>violent psychopath who knows where you live.  Code for readability.

Damn right!

--
mitch...@mdi.com (Bill Mitchell)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
William Spitzak  
View profile  
 More options Sep 26 1991, 5:12 pm
Newsgroups: comp.lang.c, comp.lang.c++
Followup-To: comp.lang.c
From: spit...@girtab.usc.edu (William Spitzak)
Date: 26 Sep 91 06:00:42 GMT
Local: Thurs, Sep 26 1991 2:00 am
Subject: Re: Usage of comma operator
I have used the comma operator a number of times with these new "modern"
system calls (MACH) that don't return the value you really want but instead
an error indicator (why not have "legal" and "illegal" values like Unix
always did?)  This is really ugly but puts the call into if statements
and assignments so I am not confused as to whether the result is used
anywhere else:

        extern errorcode sysfunction(int *returnvalue,args...);

        ...
        int junk;
        if (sysfunction(&junk,1,2,3),junk) {...

Bill Spitzak, a disillusioned hacker.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Sangrey  
View profile  
 More options Sep 26 1991, 5:12 pm
Newsgroups: comp.lang.c, comp.lang.c++
From: m...@sojurn.uucp (Mike Sangrey)
Date: 25 Sep 91 22:05:38 GMT
Local: Wed, Sep 25 1991 6:05 pm
Subject: Re: Usage of comma operator

ro...@itx.isc.com (Rob Tulloh) writes:
spcol...@uokmax.ecn.uoknor.edu (Steve Coltrin) writes:
>la...@lobster.cps.msu.edu (Mark M Lacey) writes:

Mark>I was wondering why it seems that the comma operator is so rarely used.
Mark>The only time I ever see it is in 'for' loops.  Is it really considered
Mark>*that* bad by the programming public at large?  Any comments?

I've used it to make large macros act like functions which return a value
like this:

        #define stuff(x,y)              exp1, exp2, exp3

where exp{1,2,3} are expressions.

The key point is that the value of stuff(x,y) is the value of exp3.  It's
analogous to a function doing

                return exp3;

It may be smart to parenthesize the right hand side of the macro.

--
   |  UUCP-stuff:  rutgers!devon!sojurn!mike   |  "It muddles me rather"     |
   |  Slow-stuff:  2129 Old Phila. Pike        |             Winnie the Pooh |
   |               Lancaster, Pa.  17602       |    with apologies to        |
   |  Fast-stuff:  (717) 396-9897              |             A. A. Milne     |


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "argument reuse in macros (was: Re: Usage of comma operator" by Johan Bengtsson
Johan Bengtsson  
View profile  
 More options Sep 27 1991, 8:14 am
Newsgroups: comp.lang.c, comp.lang.c++
From: j...@lulea.telesoft.se (Johan Bengtsson)
Date: 26 Sep 91 12:37:48 GMT
Local: Thurs, Sep 26 1991 8:37 am
Subject: Re: argument reuse in macros (was: Re: Usage of comma operator

mitch...@MDI.COM (Bill Mitchell) writes:
> >dwa...@stratsft.uucp (Dwayne Bailey) writes:

> >>#define mymac(a)   (foo(a), bar(a))

> >>Calls both foo() and bar(), but the "return code" of mymac is the value
> >>returned by bar().

> I've always believed that it should be CARVED IN STONE that one should
> always, always, always, without exception, code macros so that arguments
> are evaluated EXACTLY ONCE and ONLY ONCE.  Not less than once and not
> more than once.

        Well, if you do, at least give the reader of your code
        a fair warning by using all UPPER CASE for the macro.

        #define MYMAC(a) (foo(a), bar(a))

        The upper case letters are a clear warning:
        "This is a macro.  The argument may be evaluated zero,
        once or many times."

             printf("MYMAC(a++) returned %d\n", MYMAC(a++));
             printf("a ended up as %d in main\n", a);
             printf("This should not be too surprising.\n");
             printf("You have been warned!\n");

--
--------------------------------------------------------------------------- --
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden     |
| Email: j...@lulea.telesoft.se; Voice: (+46) 92075471; Fax: (+46) 92075490  |
--------------------------------------------------------------------------- --


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Usage of comma operator" by Amanda Walker
Amanda Walker  
View profile  
 More options Sep 27 1991, 2:06 pm
Newsgroups: comp.lang.c, comp.lang.c++
From: ama...@visix.com (Amanda Walker)
Date: 26 Sep 91 22:40:16 GMT
Local: Thurs, Sep 26 1991 6:40 pm
Subject: Re: Usage of comma operator
One of the places that commas (and ?:, which I actually use fairly frequently)
is in the writing of preprocessor macros which act non-astonishingly inside
'if' statements.  As a trivial example:

#define DEBUG_MSG       !debug ? 0 : printf

Twisted, but it works...

Amanda Walker                                                 ama...@visix.com
Visix Software Inc.                                     ...!uunet!visix!amanda
--
"On the whole human beings want to be good, but not too good and not quite all
 the time."        --George Orwell.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "argument reuse in macros (was: Re: Usage of comma operator" by David Fox
David Fox  
View profile  
 More options Sep 27 1991, 2:06 pm
Newsgroups: comp.lang.c, comp.lang.c++
From: f...@cs.nyu.edu (David Fox)
Date: 26 Sep 91 18:17:00 GMT
Subject: Re: argument reuse in macros (was: Re: Usage of comma operator

In article <1991Sep25.014018.23...@MDI.COM> mitch...@MDI.COM (Bill Mitchell) writes:

   I've always believed that it should be CARVED IN STONE that one should
   always, always, always, without exception, code macros so that arguments
   are evaluated EXACTLY ONCE and ONLY ONCE.  Not less than once and not
   more than once.

The assert macro violates this condition.  It would be kinda
pointless if it didn't.  I've even been hosed by trying to
do work inside an assert macro argument.  How embarassing.

-david


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "Usage of comma operator" by house ron
house ron  
View profile  
 More options Sep 28 1991, 6:55 am
Newsgroups: comp.lang.c, comp.lang.c++
From: s64...@zeus.usq.EDU.AU (house ron)
Date: 27 Sep 91 12:19:41 GMT
Local: Fri, Sep 27 1991 8:19 am
Subject: Re: Usage of comma operator

i...@prg.ox.ac.uk (Ian Collier) writes:
>I use it all the time (especially in IOCCC entries :-) ), either as in the
>above (except without the spaces :-)), or in a more complex thing, like
>   while(i++<j)
>      x=some_action(i),
>      y=other_result(i);
>      do_something(x,y),
>      etc, etc;
>   the_next_bit();
>It somehow looks better without braces. The way it is written clearly
>indicates the structure, and IMHO it doesn't matter whether the punctuation
>marks are commas or semicolons, or whether or not there are braces. It does

Well unfortunately for you it _does_ matter to the C compiler!  What you
are saying is that the next maintainer of your programs has to _read_
_carefully_and_understand_ every single line you write in order to
perform any reliable work on your program.  Now consider:

   while(i++<j)  {
      x=some_action(i),
      y=other_result(i);
      do_something(x,y),
      etc, etc;
   }
   the_next_bit();

The ground rules: NEVER NEVER NEVER NEVER omit the B____Y braces!!!!!!
ALWAYS put an open brace after the while (if etc.) closing parenthesis,
ALWAYS indent, ALWAYS return to the preceding indentation level with a
'}', and ALWAYS indent by exactly the same amount.

NOW, the meaning of the code can be reliably inferred by studying it
A LINE AT A TIME!  HAve I forgotten a brace? No, because directly under
the while I see one.  Even if there are ten pages between the while and
the }, who cares?  I am returning to a previous indentation level, so
a brace MUST be placed.  And so on.

BTW, did you notice I put one ';' in your code? No? I rest my case.

--
Regards,

Ron House.   (s64...@zeus.usq.edu.au)
(By post: Info Tech, U.C.S.Q. Toowoomba. Australia. 4350)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Baldwin  
View profile  
 More options Sep 28 1991, 9:39 am
Newsgroups: comp.lang.c, comp.lang.c++
From: jo...@searchtech.com (John Baldwin)
Date: 26 Sep 91 16:47:08 GMT
Local: Thurs, Sep 26 1991 12:47 pm
Subject: Re: Usage of comma operator
In article <1991Sep25.010136.23...@MDI.COM>
        mitch...@MDI.COM (Bill Mitchell) writes:
< In article <5...@ksr.com> j...@ksr.com (John F. Woods) writes:
<< Always code as if the guy who ends up maintaining your code will be a
<< violent psychopath who knows where you live.  Code for readability.
<
< Damn right!

Yup.

Or as someone's .sig says: "Professional programming is paranoid programming."
The rest of the system IS out to get both you AND your code!

--
John Baldwin                                        jo...@searchtech.com
search technology, inc.                             uupsi!srchtec!johnb
4725 peachtree corners cir., ste 200                jo...@srchtec.uucp
norcross, georgia  30092


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher R Volpe  
View profile  
 More options Sep 30 1991, 11:12 am
Newsgroups: comp.lang.c, comp.lang.c++
Followup-To: comp.lang.c
From: vo...@bart.crd.ge.com (Christopher R Volpe)
Date: 30 Sep 91 12:34:37 GMT
Local: Mon, Sep 30 1991 8:34 am
Subject: Re: Usage of comma operator
In article <1991Sep26.224016.2...@visix.com>, ama...@visix.com (Amanda
Walker) writes:

|>
|>#define    DEBUG_MSG       !debug ? 0 : printf

Now that's one macro definition that you better *not* wrap parentheses
around!

|>Twisted, but it works...
|>
|>Amanda Walker                                                    ama...@visix.com
|>Visix Software Inc.                                        ...!uunet!visix!amanda

==================
Chris Volpe
G.E. Corporate R&D
volp...@crd.ge.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "argument reuse in macros (was: Re: Usage of comma operator" by Geoff Clare
Geoff Clare  
View profile  
 More options Oct 1 1991, 2:12 am
Newsgroups: comp.lang.c, comp.lang.c++
From: g...@root.co.uk (Geoff Clare)
Date: 30 Sep 91 16:49:09 GMT
Local: Mon, Sep 30 1991 12:49 pm
Subject: Re: argument reuse in macros (was: Re: Usage of comma operator
In <FOX.91Sep26131...@abaco.nyu.edu> f...@cs.nyu.edu (David Fox) writes:

>In article <1991Sep25.014018.23...@MDI.COM> mitch...@MDI.COM (Bill Mitchell) writes:
>   I've always believed that it should be CARVED IN STONE that one should
>   always, always, always, without exception, code macros so that arguments
>   are evaluated EXACTLY ONCE and ONLY ONCE.  Not less than once and not
>   more than once.
>The assert macro violates this condition.  It would be kinda
>pointless if it didn't.  I've even been hosed by trying to
>do work inside an assert macro argument.  How embarassing.

It may be true that assert() on many current systems does not obey this
rule, however it's worth pointing out that both the ANSI 'C' standard and
POSIX.1 require that assert() evaluates its argument exactly once.

The only exemptions these standards make is that getc() and putc() are
allowed to evaluate their stream arguments more than once.  There is no
exemption for assert().
--
Geoff Clare <g...@root.co.uk>  (USA UUCP-only mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England.   Tel: +44 71 729 3773   Fax: +44 71 729 3273


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim McDaniel  
View profile  
 More options Oct 13 1991, 5:13 am
Newsgroups: comp.lang.c, comp.lang.c++
Followup-To: comp.lang.c
From: mcdan...@adi.com (Tim McDaniel)
Date: 9 Oct 91 18:52:06 GMT
Local: Wed, Oct 9 1991 2:52 pm
Subject: Re: argument reuse in macros (was: Re: Usage of comma operator

In article <3...@root44.co.uk> g...@root.co.uk (Geoff Clare) writes:

   It may be true that assert() on many current systems does not obey
   this rule, however it's worth pointing out that both the ANSI 'C'
   standard and POSIX.1 require that assert() evaluates its argument
   exactly once.

That happens not to be the case.  From the ANSI C standard:

   4.2 Diagnostics <assert.h>

   If NDEBUG is defined as a macro name at the point in the source
   file where <assert.h> is included, the assert macro is defined
   simply as

      #define assert(ignore) ((void) 0)

   The assert macro shall be implemented as a macro, not as an actual
   function.  If the macro definition is suppressed in order to access
   an actual function, the bahavior is undefined.

--
   "The best way to protect your liberty is to protect the liberty of others.
    Liberty is not a pie; it's an insurance program." -- Carl Kadie
Tim McDaniel                 Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Internet: mcdan...@adi.com                UUCP: {uunet,sharkey}!amara!mcdaniel


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages < Older 
« Back to Discussions « Newer topic     Older topic »