f



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
stuart
9/17/2003 8:16:33 PM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

4 Replies
1665 Views

Similar Articles

[PageSpeed] 19

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
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
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
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
Ed
9/21/2003 6:54:58 PM
Reply:

Similar Artilces:

g++ compiled C++ code called from gcc compiled C code
Hi all! In a C library compiled with gcc there is a pointer to a function defined and called from within the library. Now I'm using that library in a C++ project and I'd like to set this function pointer to a C++ function. Do I have to set the C++ function __attribute__((cdecl)) ? Are there any other things I have to worry about? See example code below. Thanks very much, Klaus Example Code: ----------------------------------------------------- *** lib.c (compiled with gcc and linked to a library): void (* logfunc)(int,char*,...); int getSomething(void) { ... logf...

compiling c code but libraries are compiled in c++
hi, We have written cunit code for testing some APIs. defination of those APIs are in c++ and .so library is created of them. when I compile my cunit code it gets compiled successfully but while liking it gives undefined reference to symbol. can anyone help me in this matter. Regards Sumit Shrivastava On 29 May 2007 04:11:14 -0700 sumit <sumit.shrivastava09@gmail.com> wrote: | We have written cunit code for testing some APIs. defination of | those APIs are in c++ and .so library is created of them. when I | compile my cunit code it gets compiled successf...

mex compiling c++ code but not c code
i get the following error when i try to compile the following code: //hello.c #include <mex.h> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { mexPrintf("Hello World!\n"); } / usr/local/MATLAB/R2012a/bin/mex: 1: eval: -c: not found mex: compile of ' "hello.c"' failed. Error using mex (line 206) Unable to complete successfully. when i use the same code but name it as hello.cpp it compiles fine & prints hello world. im using matlab 2012a,ubuntu 12.04,gcc-4.6,g++-4.6 my mex-opts.sh has C...

Cannot compile c/c++ code with Matlab R2009a Lcc compiler
Hello, I am using the lcc compiler in Matlab R2009a to create MEX files. The c/c++ files have previously been compiled and found to work in visual studio, but the matlab compiler appear to expect another syntax: class 'Sample.cpp': #include <stdio.h> #include <math.h> #include "mex.h" static const int nbrOfBands = 1; double FindShortestPath(double fromAngle, double toAngle); double FindShortestPath(double fromAngle, double toAngle, double scanDirection); double FindShortestPath(double fromAngle, double toAngle) { return findShortestPath(fro...

code that compiles in c but not in c++?
Hi,is there a code that can compile in c but not in c++ and does not use any c++ keywords as identifiers? I suspect using void* works in c but not in c++. Any suggestions? al.c...@gmail.com wrote: > Hi,is there a code that can compile in c but not in c++ and does not > use any c++ keywords as identifiers? Yes, there are plenty of examples, here is a simple one: int * iptr = malloc(10); /* Cast required in C++, frowned on in C */ C and C++ are two different languages and I wouldn't recommend trying to write code that works in both. However, if you need to know how to write C++ ...

enum bound check in compiler time in C
Hello friends, I am newbie in C. I have one enum variable for events. There are 2 types of events and I want to split them, but one can add events enums later for the both the types.I am keeping some space between two types of events. now, the problem is How to check compile time that first type of events are now overlapped with second type? Is there anyway to check for enums in compile time? any help would be appriciated. Thanks in advance, Parag paragborkar@gmail.com wrote On 04/23/07 10:55,: > Hello friends, > > I am newbie in C. I have one enum variable for events. There ar...

program that compiles in C compiler but not in C++ compiler
Hi, I need a small program that compiles in C compiler but not in C++ compiler. Thx in advans, Karthik Balaguru KBG <karthik.balaguru@lntinfotech.com> wrote: > I need a small program that compiles in C compiler but not in C++ > compiler. No problem, just send $10 to paypal@zevv.nl and I'll do your homework for you. -- :wq ^X^Cy^K^X^C^C^C^C KBG said: > Hi, > > I need a small program that compiles in C compiler but not in C++ > compiler. Can you think of any syntactic differences between C and C++? For example, what about keywords? They are very, very sen...

Can you please name a tool to check C/C++ source code against a set of coding standards?
I am not looking for a lint-like static code analyzer, I would like to check against coding standards like variable naming, capitalization, spacing, identation, bracket placement, and so on. ...

Are sun studio C/C++ compilers and Forte C/C++ compilers same ??
Is there any difference between sun studio compilers and forte compilers??? or the names have been changed??? In article <1145338052.955429.256610@v46g2000cwv.googlegroups.com>, "ameya_agnihotri" <ameyaagnihotri22@gmail.com> writes: > Is there any difference between sun studio compilers and forte > compilers??? > or the names have been changed??? One of many name changes in the product's history (including amongst others, Java somethingortheother, Workshop, Proworks/Teamworks, and probably more I've forgotten). Of course, the versions and features cha...

Compiling IDL code with a C compiler
Hi everyone, I'm interested in writing an IDL-to-C compiler, for optimization purposes. To be clear about what I'm talking about, here's what some sample IDL code would look like: ;#COMPILE gcc -O1 function EvaluateEnergy, field, area ; Type Declarations ;#field = fltarr(101, 101) ;#area = fltarr(101, 101) ;#sum = float(0.) sum = 0 for x=0, 100 do begin for y=0, 100 do begin sum = sum + field[x,y] ^ 2 * area[x, y] endfor endfor return, sum end My IDL-to-C (pre)compiler would parse the IDL pro files, looking for functions preceded by a ;#COMPILE (aka ~preprocessor di...

Compile-Time Checking for Insertion Rights on a C++ DOM Tree
While working on a DOM data structure, I noticed that only detached nodes and newly created nodes could be legally inserted into the tree. Having read a little about smart pointers and design-by- contract, I tried to enforce this condition by writing something analogous to: class Node { private: Node (std::string tag); // Clients: use Node::create() instead! ... public: static std::unique_ptr<Node> create(std::string tag); std::unique_ptr<Node> detach(); void insertNodeAsFirstChild(std::unique_ptr<Node> child); ... public: ...

Compile time of C++ vs C#
Hi, I am curious to know why C# code much faster than a similar sized C++ code. How does MSIL help? Does having a common base class like object help in reducing compile times? Thanks, Shireesh [The optimizer is usually the slowest part of a compiler and I would guess that MSIL offers fewer opportunities than native code. -John] On 2009-09-01, Shirsoft <shirsoft@gmail.com> wrote: > I am curious to know why C# code much faster than a similar sized C++ > code. How does MSIL help? Does having a common base class like object > help in reducing compile times? Which C++ compiler? ...

Compile C Code With A CPP Compiler?
Hey all, I'm working with some legacy C code and I would like to compile it as a CPP file. I get the following error message: driver.cpp:87: cannot convert `void *' to `GenericStruct *' in assignment Reading through the web I've come across vague references to the 'void' issue between C and C++, I don't know C++ well and would appreciate any pointers or references which might help me out. Thanks! entropy email_entropy123@yahoo.com (entropy123) wrote in news:90cdce37.0309301057.25d7506f@posting.google.com: > I'm working with some legacy C code and I w...

Compiling Matlab code to C++ code
Hi, I'm trying to compile matlab code into C++. I ran mbuild -setup to use MS VS.(on a side note, can Matlab use g++ instead? it only gave options for MS VS and LCC) Then I tried 'mcc -m add -d bin -v' The program is simple: function add(As, Bs) A = str2num(As); B = str2num(Bs); C = A + B; But I run into this non descriptive error message: Generating MATLAB path for the compiled application... Created 34 path items. Depfun main loop converged in 2 iterations, total number of files = 11 Begin validation of MEX files: Thu Feb 22 09:04:57 2007 End validation of MEX files: Thu Fe...

running time/speed of .m code compiled and deployed in c
Can anyone let me know whether a .m code compiled and included as a library/header file in C (application deployment) runs faster as compared to running on matlab environment? "Rubal " <rub_dua_06@yahoo.com> schrieb im Newsbeitrag news:fm6oen$61m$1@fred.mathworks.com... > Can anyone let me know whether a .m code compiled and > included as a library/header file in C (application > deployment) runs faster as compared to running on matlab > environment? No, it won't. Since R14 the compiled code and the interpreted code run on same speed, because the code is not...

How to compile this C Code in Dev-C++??
I have done the following: New Project -> Console Application -> C Project. Then I get the following text: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { system("PAUSE"); return 0; } But where do I write my own C code? I have written the following code: void c(unsigned int n) { while (n > 1) if ((n & 1) == 0) n = n/2; else n = 3 * n + 1; } But where should I put it and how do I compile it? js * JS: > I have done the following: New Project -> Console Application -> C Project. Off-topic on two groun...

C++0x/1x exception specifications proposal: Compile-time checked
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... } and getting a compile time error saying something like: "Error: void somefunc(void) throw(): Wrong exception specification. somefunc can throw std::bad_alloc, std::range_error". That is make the compiler to check exception specifications for errors too. Ioannis A. Vranos In article <fmvvf1$1i2i$1@ulysses.noc.ntua.gr>, ivranos@no.spamfreemail.nospam.gr says... > Perhaps a mechanism can be introduced in the C++0x/1...

C++0x/1x exception specifications proposal: Compile-time checked
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... } and getting a compile time error saying something like: "Error: void somefunc(void) throw(): Wrong exception specification. somefunc can throw std::bad_alloc, std::range_error". That is make the compiler to check exception specifications for errors too. Ioannis A. Vranos -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] Ioannis Vranos w...

using Dev-C++ to compile ONLY C code ?
Hi there, don't know if it's the right group, but I'll try anyway. Sorry if I'm OT, anybody can be so patient to tell me the right group ? Thanks :) Anyway, the question is: I know I can write C programs using a C++ environment like Dev-C++. However, I'd like to know if there are some options that allow Dev to ignore C++ syntax and act as a C-only compiler. Is this possible ? And, if not, can anybody suggest me a free C compiler under Windows ? Thanks a lot. -- Emanuele Blanco PGP Key Available - http://studenti.unina.it/~emblanco/key.asc "Emanuele Blanco"...

Why would someone use c++ compiler on a C code?
Would it suppress errors? Is he trying to hide errors in his code? On Apr 7, 9:56 pm, 2005 <FW3...@sbcglobal.net> wrote: > Would it suppress errors? > > Is he trying to hide errors in his code? He is using g++ on a *.c code! Also what is so different between gcc & cc compiler - any advantages? 2005 wrote: > Would it suppress errors? > > Is he trying to hide errors in his code? Probably the reverse, C++ and its compilers are more pedantic about a number of issues, particularly type safety. Do bear in ming there are sometimes obscure semantic differences betw...

Compile c/c++ code on a pocket pc?
Hi, my name is Sean and I was wondering if it's possible to compile c/c++ code on a pocket pc running windows ce. Is it possible? On 25 Apr 2005 07:56:34 -0700, "twoeyedhuman1111" <twoeyedhuman1111@gmail.com> wrote: >Hi, my name is Sean and I was wondering if it's possible to compile >c/c++ code on a pocket pc running windows ce. Is it possible? The closest I know about is PocketC: http://www.orbworks.com/wince/index.html I've never tried it, so I can't say more. The only other C/C++ compilers I know about require cross-compilation (develop and build on desktop, run on handheld). I _think_ gnu has some support. Microsoft provides eVC, which is available free (_large_ download); I don't know the web location offhand, but your can probably find it by going to www.microsoft.com and searching for evc (search box in top right corner). For some other possibilities, see: http://www.cewindows.net/developer/languages.htm ----------------------------------------- To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message). Robert E. Zaret, eMVP PenFact, Inc. 500 Harrison Ave., Suite 3R Boston, MA 02118 www.penfact.com "twoeyedhuman1111" <twoeyedhuman1111@gmail.com> wrote: > > > Hi, my name is Sean and I was wondering if it's possible to compile > c/c++ code on a pocket pc running windows ce. Is it possible? there is a port of gcc called pgcc th...

Sequitur C/C++ code
Hello, Has perhaps anyone tried the Sequitur C/C++ code available at http://sequitur.rutgers.edu/sequitur (follow the link "Full source") ? Judging from the Makefile, it is supposed to be compiled using gcc, but I have tried several versions of gcc under both Linux and Windows, and it either doesn't compile (there are include files required that do actually not exist), or it does, but crashes when ran. I would appreciate it if someone who successfully managed to compile the code and run the resulting program, told me using which compiler/settings/platform/... they did it. Tha...

Compile C/C++ code and connect it to matlab
Hello, I want to compile a C++ code and connect it to matlab. Can anyone pls tell me how i should do it. I tried doing it using mex with some built in matlab c codes, but these c codes are very diff from what i have written. My c code is the normal c code that we write.I am naive regarding this and so kindly explain as much as possible. Thanks, Prads On 27 Okt, 02:57, prads <kashya...@gmail.com> wrote: > Hello, > I want to compile a C++ code and connect it to matlab. Can anyone pls tell me how i should do it. I tried doing it using mex with some built in matlab c codes, but thes...

is c the best? why does everything else compile to c?
Is it jsut the truth that you have to learn c? I know almost no programming and want to learn and build killer apps 1 people say use java its the best for getting large complex thgns done 2 learn perl because it has msot code online and great frameworks and is faster to develop than java 3 learn clisp becauase it has most power and real macros 4 learn haskell because it has lazy evaluation and strong types eliminate errors 5 learn ruby because it maximizes programming ease and has good libraries 6 learn tcl beacuase it is simple and has gui abilities 7 learn smalltalk becasue oo i sbest way to...

Web resources about - could if/else avoid syntax checking compile time unreachable code? - comp.lang.c++.moderated

Andy Murray strives to grasp the unreachable vision
Andy Murray is a peculiar man to watch on the tennis court. He's of more intrigue and vulnerability than Novak Djokovic, who's too good at being ...

Idea Factory CEO: Imageepoch CEO Is Unreachable
Idea Factory CEO reached out to Twitter to locate Ryohei Mikage


Obama, Republicans and Lofty, Unreachable Goals - Bloomberg View
Obama's message was "We need to stop getting caught up in partisan battles, and compromise on sensible policies to help the middle class and ...

Two and a Half Men Star Jon Cryer Talks SAG Nom, Charlie Sheen and "Unreachable" Ashton Kutcher
Jon Cryer doesn't like getting calls very early in the morning—not after all the drama Two and a ...

Dark Energy Renders 97% Of The Galaxies In Our Observable Universe Permanently Unreachable
Video When you look out at a star whose light arrives after traveling towards you for 100 years, you're seeing a star that's 100 light years ...


Richard Branson: Conquering the 'Unreachable' Parts of Our Planet and Beyond...
This week Jim Cameron has shown the world it is possible to take 21st Century camera technology to the depths he has sparked humankind's curiosity ...

Unreachable In Mali: Thousands Suffer In Al Qaeda’s Newest Stronghold
A new base for Al Qaeda has emerged in the heart of the African Sahel, where no state army has yet been able to contest its presence.

Lionel Messi To Leave ‘Unreachable’ Record
Lionel Messi will leave an “unreachable” La Liga scoring record, according to Luis Enrique. The Barcelona coach was speaking after the Argentinian ...

Resources last updated: 3/9/2016 12:44:34 PM