|
|
could if/else avoid syntax checking compile time unreachable code?
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: How to check whether malloc has allocated memory properly in case ...In my code examples How to check whether malloc has allocated ... return malloc(n==0 ? 1 : n);} I avoid this ... Compilers would catch it at compile time if ... How to strip comments out of code - comp.lang.java.programmer ...Check it out at Google.com ... equivalent source code from the bytecode? (Keywords: Type erasure, compile-time ... use the following code, but I want to avoid such a time ... writing robust software? - comp.lang.c++.moderatedI could avoid uninitialized member ... of any > particular unreachable object may be delayed a very long time. ... it be destructed at that time, but somewhere, some code ... Does PAUSE have any Side Effect ?? - comp.lang.fortran... do anything else ?? 3) Here's an abbreviated sample code ... bound checking on the compiler when you are developing code ... to avoid warnings at compile time about ... memset() bug for 32-bit code with sun4v ? - comp.unix.solaris ...... have access to a solaris to check if the syntax is ... I'd be interested if any others could compile this bit of code ... Most uses of memset() pass a compile- time ... Intel Visual Fortran Error Message - comp.lang.fortran... don't have to memorize a list of keywords to avoid ... from a new program project that refuses to compile and run. I could ... see a Help -> About in VS 2008 where I can check ... problem with mixed c and fortran code - comp.lang.fortran ...... to have its length known at compile time ... Maybe someone else can check. Hope you are ... DEC$ stuff scares me, though that could just be because the syntax ... Const constructor - comp.lang.c++.moderatedDoes anyone else have the same experience, or was my ... of elements your ArraySlice points to to > > avoid code ... SOLUTION: compile time array size using type only - comp ... Where did Fortran go? - comp.lang.fortran... clean syntax that are very >easy to read, and Python code is ... else. But that's flawed thinking. F77 - no mandated compile time error ... inherent compile time checking ... gcc errors on solaris 10 - comp.unix.solarisApart from the syntax used to set it, it is nothing ... the gcc compiler included with Solaris 10, or compile the code ... however I got a different set of errors that time. Handling PL/SQL Errors... is selected, and there is no ELSE ... your programs more robust and avoid problems at run time, you can turn on checking ... code displays ALTER PROCEDURE unreachable_code COMPILE ... compile warn??? (Unreachable code detected) - Visual C# - Windows TechCheck if something got wrong in there. You could ... this code to work. Can you help me avoiding ... syntax. Tag: Visual C# IDE compile warn??? (Unreachable code ... 7/20/2012 1:45:06 PM
|
|
|
|
|
|
|
|
|