could if/else avoid syntax checking compile time unreachable code?

  • Follow


I understand most optimisers will not code up blocks which are known at
compile time not to execute.

Should this behaviour be extended in some future standard to complete
ignoring of the unreachable code?  Perhaps restricted to {if, else, switch,
case}?

e.g.

if(0)
{
this is not syntax checked
}
else
{
// compiled code
}

This should allow much shorter and clearer implimentation of much current
messy templated traits code.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply stuart 9/17/2003 8:16:33 PM

On 17 Sep 2003 16:16:33 -0400, stuart macgregor
<stuart.191@ntlworld.com> wrote:

 >I understand most optimisers will not code up blocks which are known at
 >compile time not to execute.
 >
 >Should this behaviour be extended in some future standard to complete
 >ignoring of the unreachable code?  Perhaps restricted to {if, else, switch,
 >case}?
 >
 >e.g.
 >
 >if(0)
 >{
 >this is not syntax checked
 >}
 >else
 >{
 >// compiled code
 >}

What about: the following?

if(0)
{
this is not syntax } checked
}
else
{
// compiled code
}

Surely the syntax /has/ to parse for the compiler to know where the
reachable code resumes?

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Tim 9/18/2003 9:56:33 AM


On 17 Sep 2003 16:16:33 -0400, stuart macgregor
<stuart.191@ntlworld.com> wrote in comp.lang.c++.moderated:

 > I understand most optimisers will not code up blocks which are known at
 > compile time not to execute.
 >
 > Should this behaviour be extended in some future standard to complete
 > ignoring of the unreachable code?  Perhaps restricted to {if, else, switch,
 > case}?
 >
 > e.g.
 >
 > if(0)
 > {
 > this is not syntax checked
 > }
 > else
 > {
 > // compiled code
 > }

Since you're asking for opinions, mine is a resounding NO.  If nothing
else, you could get nasty surprises if/when the time comes that you do
want that section compiled.

If you don't want the code compiled, you have two choices:

/*
  this is not syntax checked
*/

.....or:

#if 0
   must parse to valid pp tokens, but need not be syntactically
   or semantically valid C++
#endif

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Jack 9/18/2003 10:01:37 AM

On 17 Sep 2003 16:16:33 -0400, stuart macgregor
<stuart.191@ntlworld.com> wrote:

>I understand most optimisers will not code up blocks which are known at
>compile time not to execute.
>
>Should this behaviour be extended in some future standard to complete
>ignoring of the unreachable code?  Perhaps restricted to {if, else, switch,
>case}?
>
>e.g.
>
>if(0)
>{
>this is not syntax checked

     Say what?

     How are you doing to determine what the boundaries of the
unreachable block are if you do not check for syntax?  Did you mean
that the section should not be checked for semantics?

>}
>else
>{
>// compiled code
>}
>
>This should allow much shorter and clearer implimentation of much current
>messy templated traits code.

Sincerely,

Gene Wirchenko

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Gene 9/19/2003 10:00:51 AM

As others have pointed out, the unreachable code has to be syntax
checked.  But it might not need to be typechecked or checked for names
that are in scope (calls to nonexistent functions, etc).

However it would be too confusing if the normal 'if' started to not
give errors for code that the compiler considers unreachable (and
different compilers will have different levels of intelligence on
that).  Better to have a separate 'cif' (compile-time if) where the
condition must be a compile-time expression.

-- 
Ed Avis <ed@membled.com>


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Ed 9/21/2003 6:54:58 PM

4 Replies
663 Views

(page loaded in 0.083 seconds)

Similiar Articles:













7/20/2012 1:45:06 PM


Reply: