home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!mips!sdd.hp.com!usc!sol.ctr.columbia.edu!destroyer!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.lang.c
- Subject: Re: converting C 'for' to PASCAL 'FOR'
- Summary: bad, foolish, evil idea
- Message-ID: <1992Jul28.220307.13267@organpipe.uug.arizona.edu>
- Date: 28 Jul 92 22:03:07 GMT
- References: <1992Jul28.151937.247@falcon.navsses.navy.mil>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 59
- In-Reply-To: huynh@falcon.navsses.navy.mil
-
- In article <1992Jul28.151937.247@falcon.navsses.navy.mil>, huynh@falcon writes:
- >I am curious if there is a way to translate the "C" for(i,start,last,incr)
- >statement into the PASCAL FOR i = start to last DO (* incr = 1 *).
-
- I'm not sure exactly what you want here.
-
- The Pascal code
-
- for i := lo to hi do body ;
-
- Is (mostly) equivalent to this C code:
-
- for( i = lo ; i <= hi ; i++ ) body ;
-
- If you want to be pedantic, you could do this:
-
- for( index = lo ; index < hi ; index++ ) { int i = index ; body ; }
-
- (assuming `index' is not referenced anywhere in `body').
-
-
- If you want to go the other way, the C code
-
- for( start_expr ; done_expr ; inc_expr ) body ;
-
- Has no direct equivalent in Pascal. The best you can do is
-
- start_expr ;
- while done_expr do begin body ; inc_expr ; end ;
-
- >I am interested in doing this using the #define statement.
-
- No. PLEASE don't do this. It is a bad, vile thing to use the preprocessor
- to re-define the language to make it look like some other language.
-
- Trust me, you're better off using C's control structures as they stand.
- You're programs will be easier to understand, and you'll learn C a lot
- quicker if you don't try to pretend that it's Pascal.
-
- This means that "cute" processor tricks like
- #define BEGIN {
- #define END }
- #define REPEAT do {
- #define UNTIL(x) } while( !(x) )
- #define AND &&
- #define OR ||
- /* etc */
-
- Are also a bad idea. In many ways, C and Pascal are very similar
- languages. But it is a mistake to assume that they are the same.
- Their differences are important too, and the above trickery not only
- obscures differences between the two languages, it also makes code
- harder to understand, particularly for non-Pascal programmers.
-
- --
- You unlock this door with the key of imagination. Beyond it is another
- dimension: a dimension if sound, a dimension of sight, a dimension of mind.
- You're moving into a land of both shadow and substance, of things and ideas.
- You've just crossed over into... the Twilight Zone.
-