COMPGROUPS.NET   Search  Post Question   Groups  About  Contact  Register | Login

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

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 Header Report as Spam



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 Header Report as Spam

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 Header Report as Spam

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 Header Report as Spam

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 Header Report as Spam

4 Replies
377 Views




Similiar Articles:
















5/18/2012 10:48:41 AM


Reply:
Alert me when someone responds to this posting.