Topic: C++0x Wish List (deprecate null statement)


Author: Allan_W@my-dejanews.com (Allan W)
Date: Fri, 2 Aug 2002 21:11:12 GMT
Raw View
> > Stephen Howe wrote:
> > > I do not wish to see null statements deprecated, I use this
> > > all the time. I would write that as
> > >
> > > while (*(out++)=*(in++))
> > >     ;

> "David Schwartz" <davids@webmaster.com> wrote
> > This could just as well be:
> >
> > while (*(out++)=*(in++)) { }
> >
> > No null statement needed.

"Joe Gottman" <jgottman@carolina.rr.com> wrote
> Does this work inside a for loop?  That's one place where
> I use null statements all the time. For instance:
>     for (int n = 0; /* No condition */; ++n) {
>              /* Complicated code that eventually calls break */
>      }

I do not propose breaking that, or even deprecating it.

The middle part of a for statement is a condition, not a
statement. The reason you can omit it is that the syntax for
the for() statement declares the condition to be optional. (6.5)
Leaving it out is not the same thing as using a null statement.

However, even here there is an alternative:
   for (int n=0; true; ++n)
does exactly what you want, and I suspect (haven't tested it)
that even with optimizations turned off, most compilers will
generate identical code for this case.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: David Schwartz <davids@webmaster.com>
Date: Wed, 31 Jul 2002 15:02:27 GMT
Raw View
Stephen Howe wrote:

> I do not wish to see null statements deprecated, I use this all the time. I
> would write that as
>
> while (*(out++)=*(in++))
>     ;
>
> Stephen Howe

 This could just as well be:

while (*(out++)=*(in++)) { }

 No null statement needed.

 DS

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Joe Gottman" <jgottman@carolina.rr.com>
Date: Thu, 1 Aug 2002 17:54:57 GMT
Raw View
"David Schwartz" <davids@webmaster.com> wrote in message
news:3D478FFA.75E92A7@webmaster.com...
> Stephen Howe wrote:
>
> > I do not wish to see null statements deprecated, I use this all the
time. I
> > would write that as
> >
> > while (*(out++)=*(in++))
> >     ;
> >
> > Stephen Howe
>
> This could just as well be:
>
> while (*(out++)=*(in++)) { }
>
> No null statement needed.
>

   Does this work inside a for loop?  That's one place where I use null
statements all the time. For instance:
    for (int n = 0; /* No condition */; ++n) {
             /* Complicated code that eventually calls break */
     }

Joe Gottman



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Michiel.Salters@cmg.nl (Michiel Salters)
Date: 22 Jun 2002 00:35:06 GMT
Raw View
"Carl Daniel" <cpdaniel@pacbell.net> wrote in message news:<i_1Q8.998$J42.91085000@newssvr14.news.prodigy.com>...
> "Michiel Salters" <Michiel.Salters@cmg.nl> wrote

> > I commonly write
> >
> > catch (Ex)
> > { ; }
>
> Just out of curiousity, why the ; in there?
>
> If I encountered { ; } in code, I'd be suspicious that something had been
> accidently deleted, while { } is, to me at least, clearly an intentionally
> empty statement.

It's clearly a matter of preference. Accidental deletion would look like
{
  ;
}
or
{
}
or
{ }
to me; if I use the mouse to select text to delete text I won't be able
to select the newline after both { and ; while leaving the ; in place.
Therefore getting from
{
  foo();
}
to
{ ; }
takes at least two edits, which to me means a more deliberate action.

Regards,
--
Michiel Salters

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Stephen Howe" <SPAMstephen.howeGUARD@tnsofres.com>
Date: Sat, 22 Jun 2002 17:08:12 GMT
Raw View
"Allan W" <Allan_W@my-dejanews.com> wrote in message
news:23b84d65.0206181331.3d79ce9b@posting.google.com...
> The null statement is error-prone, because it's second nature to
> use a semicolen at the end of every statement -- even where it
> doesn't belong:
>
>     if (a==b);
>         TheyAreEqual(); // Oops! Called when it shouldn't be!
>
> We can't simply make the null statement illegal -- too much legacy
> code. But there are already alternatives today, so we can deprecate it.
>
> My favorite alternative is the "continue" statement.
>     while (*(out++)=*(in++)) ; // Old way

I do not wish to see null statements deprecated, I use this all the time. I
would write that as

while (*(out++)=*(in++))
    ;

Stephen Howe


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Daniel James <internet@nospam.demon.co.uk>
Date: Thu, 20 Jun 2002 17:30:43 GMT
Raw View
In article <23b84d65.0206181331.3d79ce9b@posting.google.com>,
Allan W wrote:
> We can't simply make the null statement illegal -- too much
> legacy code.

.. and too many debugging macros that eveluate to null
statements in release builds ...

> A special case of this is what some people THINK that the term
> "null statement" means -- use NULL as the constant expression.
>
>     while (*(out++)=*(in++)) NULL; // New way #3

I like that.

Algol68 had the keyword SKIP for exactly this purpose:

  WHILE CHAR c; read(c); is white space(c) DO SKIP OD;

.. but it was syntactic sugar - one could substitute any
constant expression and the result would be silently voided.

  WHILE CHAR c; read(c); is white space(c) DO 0 OD;

Cheers,
 Daniel.


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Carl Daniel" <cpdaniel@pacbell.net>
Date: Thu, 20 Jun 2002 17:31:29 GMT
Raw View
"Michiel Salters" <Michiel.Salters@cmg.nl> wrote in message
news:cefd6cde.0206190346.697f276@posting.google.com...
> Isn't this primarily a QoI thing? If your compiler issued a
> "Warning: if-statement misses controlled statement (extra ';' ?)"
> would you still want the null-statement deprecated?
>
> I commonly write
>
> catch (Ex)
> { ; }
>

Just out of curiousity, why the ; in there?

If I encountered { ; } in code, I'd be suspicious that something had been
accidently deleted, while { } is, to me at least, clearly an intentionally
empty statement.

-cd


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: allan_W@my-dejanews.com (Allan W)
Date: Thu, 20 Jun 2002 17:32:11 GMT
Raw View
Michiel.Salters@cmg.nl (Michiel Salters) wrote
> Allan_W@my-dejanews.com (Allan W) wrote
> > The null statement is error-prone, because it's second nature to
> > use a semicolen at the end of every statement -- even where it
> > doesn't belong:
> >
> >     if (a==b);
> >         TheyAreEqual(); // Oops! Called when it shouldn't be!
> >
> > We can't simply make the null statement illegal -- too much legacy
> > code. But there are already alternatives today, so we can deprecate it.
>
> Isn't this primarily a QoI thing? If your compiler issued a
> "Warning: if-statement misses controlled statement (extra ';' ?)"
> would you still want the null-statement deprecated?

I suppose you could say this about any request to have some language
element deprecated. Compilers can always emit warning messages, even
when the code doesn't do anything illegal or deprecated.

I'd like something more official, though. As long as this syntax is
officially blessed, people are going to keep doing it, which means
that compilers are going to have to allow it, even if there are
diagnostics.

> I commonly write
>
> catch (Ex)
> { ; }
>
> and I think it's clear what this does; I don't think this usage should
> be deprecated.

As Michael Glassford pointed out, it's just as easy to use an
empty compound statement:

    catch (Ex)
        {}

Surely this is no less clear.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: allan_W@my-dejanews.com (Allan W)
Date: Thu, 20 Jun 2002 17:32:13 GMT
Raw View
"Michael Glassford" <glassfordm_nospam@hotmail.com> wrote in message news:<uh14grqp9u2gb9@corp.supernews.com>...
> How about New way #4?
>
> while (*(out++)=*(in++)) {} // New way #3

A good point.

Are there any places where the null statement is valid, but an
empty compound statement is not? The only place I can think of
is inside a for() statement
    for (bool done=false; !done; {}) // Not valid here
That's not a trouble-prone place anyway.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: allan_W@my-dejanews.com (Allan W)
Date: Thu, 20 Jun 2002 19:52:53 CST
Raw View
> Allan W wrote:
> > We can't simply make the null statement illegal -- too much
> > legacy code.

Daniel James <internet@nospam.demon.co.uk> wrote
> .. and too many debugging macros that eveluate to null
> statements in release builds ...

Such as common definitions of ASSERT:

#ifdef DEBUG
  #define ASSERT(x) if(x);else __assert(##x,__FILE__,__LINE__)
#else
  #define ASSERT(x)
#endif

My replacement would be simple:
#ifdef DEBUG
  #define ASSERT(x) if(x){}else __assert(##x,__FILE__,__LINE__)
#else
  #define ASSERT(x) 0
#endif

The equivalent change in third-party code wouldn't happen overnight --
but I'm not talking about removing null statements overnight, just
deprecating them. If a compiler issued a warning message for use of
the null statement, there would no doubt be a compile option to disable
that warning. Eventually we could remove null statements from our code
and then stop using that option.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Tom Puverle" <tp225@cam.ac.uk>
Date: Fri, 21 Jun 2002 15:36:16 GMT
Raw View
"Allan W" <Allan_W@my-dejanews.com> wrote in message
news:<23b84d65.0206181331.3d79ce9b@posting.google.com>...

> while (*(out++)=*(in++)) NULL; // New way #3

>

How about "{}" as a null statement?

Tom



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Allan_W@my-dejanews.com (Allan W)
Date: Tue, 18 Jun 2002 21:47:45 GMT
Raw View
The null statement is error-prone, because it's second nature to
use a semicolen at the end of every statement -- even where it
doesn't belong:

    if (a==b);
        TheyAreEqual(); // Oops! Called when it shouldn't be!

We can't simply make the null statement illegal -- too much legacy
code. But there are already alternatives today, so we can deprecate it.

My favorite alternative is the "continue" statement.
    while (*(out++)=*(in++)) ; // Old way
    while (*(out++)=*(in++)) continue; // New way #1

The continue statement can't always be used -- sometimes intentional
null statements aren't at the end of a loop. But we can instead use
a constant expression with no side effects:

    while (*(out++)=*(in++)) 1; // New way #2

A special case of this is what some people THINK that the term
"null statement" means -- use NULL as the constant expression.

    while (*(out++)=*(in++)) NULL; // New way #3

If you've ever spent a hard day tracking down a bug, and it turned
out to be an extra semicolen -- you'll probably want to deprecate
the null statement.

Every COBOL programmer has horror stories about a program with a
missing or extra period. Let's make sure that C++ doesn't have that
same problem with semicolens.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Michiel.Salters@cmg.nl (Michiel Salters)
Date: 19 Jun 2002 15:15:11 GMT
Raw View
Allan_W@my-dejanews.com (Allan W) wrote in message news:<23b84d65.0206181331.3d79ce9b@posting.google.com>...
> The null statement is error-prone, because it's second nature to
> use a semicolen at the end of every statement -- even where it
> doesn't belong:
>
>     if (a==b);
>         TheyAreEqual(); // Oops! Called when it shouldn't be!
>
> We can't simply make the null statement illegal -- too much legacy
> code. But there are already alternatives today, so we can deprecate it.

Isn't this primarily a QoI thing? If your compiler issued a
"Warning: if-statement misses controlled statement (extra ';' ?)"
would you still want the null-statement deprecated?

I commonly write

catch (Ex)
{ ; }

and I think it's clear what this does; I don't think this usage should
be deprecated.

Regards,
--
Michiel Salters

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Michael Glassford" <glassfordm_nospam@hotmail.com>
Date: 19 Jun 2002 15:15:17 GMT
Raw View
How about New way #4?

while (*(out++)=*(in++)) {} // New way #3

"Allan W" <Allan_W@my-dejanews.com> wrote in message
news:23b84d65.0206181331.3d79ce9b@posting.google.com...
> The null statement is error-prone, because it's second nature to
> use a semicolen at the end of every statement -- even where it
> doesn't belong:
>
>     if (a==b);
>         TheyAreEqual(); // Oops! Called when it shouldn't be!
>
> We can't simply make the null statement illegal -- too much legacy
> code. But there are already alternatives today, so we can deprecate it.
>
> My favorite alternative is the "continue" statement.
>     while (*(out++)=*(in++)) ; // Old way
>     while (*(out++)=*(in++)) continue; // New way #1
>
> The continue statement can't always be used -- sometimes intentional
> null statements aren't at the end of a loop. But we can instead use
> a constant expression with no side effects:
>
>     while (*(out++)=*(in++)) 1; // New way #2
>
> A special case of this is what some people THINK that the term
> "null statement" means -- use NULL as the constant expression.
>
>     while (*(out++)=*(in++)) NULL; // New way #3
>
> If you've ever spent a hard day tracking down a bug, and it turned
> out to be an extra semicolen -- you'll probably want to deprecate
> the null statement.
>
> Every COBOL programmer has horror stories about a program with a
> missing or extra period. Let's make sure that C++ doesn't have that
> same problem with semicolens.
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]
>


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]