HDTenEightyP/NetNews huggingface dataset:
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: converting C 'for' to PASCAL 'FOR'
Summary: bad, foolish, evil idea
Date: 28 Jul 92 22:03:07 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

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.
From: chris.lincoln@wugate.wustl.edu!travel (Chris Lincoln) 
Newsgroups: comp.lang.c
Subject: #include file dependancie
Date: 24 Jul 92 06:47:00 GMT
Distribution: world
Organization: Travel Online, St. Louis, MO, USA
Reply-To: chris.lincoln@wugate.wustl.edu!travel (Chris Lincoln) 

AG.Newsgroups: comp.unix.programmer,comp.unix.questions,comp.lang.c
AG.From: ajg@controls.ccd.harris.com (Arnold Goldberg)
AG.Subject: #include file dependancies
AG.Message-ID: <AJG.92Jul22114544@sp1.ccd.harris.com>
AG.Date: Wed, 22 Jul 1992 16:45:44 GMT

AG.We here have a very large source tree.

AG.What I'm looking for is a script or utility that will somehow tell
AG.me which #include files are not actually needed for a source file.

  Gimpel's PC-lint 5.0 provides this information.  It is available
  for around $80 for MS-DOS.  I believe the C-shrouded *NIX versions
  sell for a few hundred dollars.  Damn good program.
---
 . SLMR 2.0 . America's "Gross National Product": broccoli
                                                                           
Newsgroups: comp.lang.c
From: mitchell@mdd.comm.mot.com (Bill Mitchell)
Subject: Re: Pointers outside of array boundary
Bcc:  mitchell
Reply-To: mitchell@mdd.comm.mot.com (Bill Mitchell)
Organization: Motorola, Mobile Data Division - Seattle, WA
Date: Wed, 29 Jul 1992 21:40:10 GMT

in comp.lang.c, mjs@hubcap.clemson.edu (M. J. Saltzman) said:


>In article <mjd.712419017@hal> mjd@hal.gnu.ai.mit.edu (Sievan Janacziewski) writes:
>>>[about 1-based indexing]
>>[...]
>>If 0-based arrays are unclear to your correspondent, then he or she
>>should practice more, so that they become more familiar, rather than
>>resorting to obfuscation to cover his or her inadequacies as a programmer.
>
>While I agree with this sentiment in general, I also have been faced
>with the problem of implementing complicated combinatorial algorithms
>from specifications that describe the algorithms using a 1-based
>indexing scheme.  From a purely aesthetic point of view, re-expressing
>the alogirthms to use 0-based indexing *clearly and correctly* seems
>like a worthwhile goal, but practical considerations (like having to
>get the work done) often take priority, and kluges to fixup the
>results of index calculations often serve to obfuscate the code and
>introduce bugs.  In this case, wasting the 0th element of an array
>seems like a relatively small price to pay, if that's the only way 
>to write 1-based code.
>

I agree.  So, apparently, would a couple of programmers named Kernighan
and Ritchie; who are generally regarded as having adequate programming
skills.

From k&r-2, pages 111 and 112:

static char daytab[2][13] = {
    {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
[...]
We started the array daytab with a column of zero so that the month numbers
can run from the natural 1 to 12 instead of 0 to 11.  Since space is not at
a premium here, this is clearer than adjusting the indices.

[ end of the quotes]

So, there are situations where 1-based arrays make good sense.  In those
situations, 1-based arrays should be used.

However, except for those special situations, zero-based arrays should be
used because that is what programmers maintaining the code will expect.

The decision between 1-based and 0-based arrays is a judgement call,
and that decision could be made either way depending on factors such
as maintainability considerations, ease of porting a previous implementation
from another language, implementing an algorithm from a published
description, etc.

-- 
mitchell@mdd.comm.mot.com (Bill Mitchell)
From: raeker@tc4.fi.ameslab.gov (Todd J. Raeker)
Newsgroups: comp.lang.c
Subject: array element swap help
Date: 30 Jul 92 16:16:48 GMT
Reply-To: raeker@tc4.fi.ameslab.gov (Todd J. Raeker)
Organization: Ames Laboratory

I need to swap values in an array while sorting it, currently I am doing
the swap as follows


            temp = ztmp[j];
            ztmp[j] = ztmp[k];
            ztmp[k] = temp;


This is currently a bottleneck in my program and I need to figure a 
better way to do due this.  Since I am not an advanced c programmer, this
is the best I could come up with, is there a more efficient way?

Thanks.

-- 


Dr. Todd J. Raeker           |      307B Wilhelm Hall
raeker@tc4.fi.ameslab.gov    |      Iowa State University
Phone (515)-294-9927         |      Ames Laboratory, USDOE
FAX   (515)-294-5204         |      Ames, Iowa 50011
Newsgroups: comp.lang.c
From: mitchell@mdd.comm.mot.com (Bill Mitchell)
Subject: Re: fast circle
Bcc:  mitchell
Reply-To: mitchell@mdd.comm.mot.com (Bill Mitchell)
Organization: Motorola, Mobile Data Division - Seattle, WA
Distribution: usa
Date: Thu, 30 Jul 1992 13:48:22 GMT

in comp.lang.c, jle9162@venus.tamu.edu (ECKHARDT, JASON LEE) said:


>
>  I'm looking for a FAST circle algorithm...'C' code or pseudocode, it
>doesn't matter, as long as it cooks.
>
>Thanks, jason.

Dr. Dobbs Journal had an ongoing mail-in discussion about this several
years ago.  Went on for 6 months or more.  Don't remember the time
period involved, but it shouldn't be hard to find if you can get a
stack of back issues at your local library and rummage thru them.
-- 
mitchell@mdd.comm.mot.com (Bill Mitchell)
From: pinard@IRO.UMontreal.CA (Francois Pinard)
Newsgroups: comp.lang.c
Subject: Re: Balancing Binary Search Trees
Date: 31 Jul 92 19:26:29 GMT
Organization: Universite' de Montre'al

In article <1992Jul29.014821.2675@samba.oit.unc.edu> Alan.Tai@bbs.oit.unc.edu (Alan Tai) writes:

   Could someone please post some example code for balancing binary
   trees [...]

There are probably many such packages flying around.

For one, I made a set of binary tree routines which I will provide on
request (copylefted code, however).  One unusual feature is that they
can work in two modes, one in which the nodes are all allocated in one
big array of free nodes mallocated once, the other in which all nodes
can be allocated separately.
--
Franc,ois Pinard        ``Vivement GNU!''        pinard@iro.umontreal.ca
(514) 588-4656                                    ...!uunet!iros1!pinard
Consider joining the League for Programming Freedom.  Email for details!
From: chuckb@milton.u.washington.edu (Chuck Bass)
Newsgroups: comp.lang.c
Subject: ftp site for mkmf?
Date: 25 Jul 92 00:05:36 GMT
Organization: University of Washington


Does anyone know where an ftp site for mkmf is? One the has
build make files for c or c++ programs?  We have ANSI c and a
g++ compiler.

Thanks...

Chuck Bass
From: EE117@LIVERPOOL.AC.UK
Newsgroups: comp.lang.c
Subject: don't try this at home kids...
Date: 16 Jul 92 15:40:11 GMT
Organization: University of Liverpool

I recently ran this Mickey Mouse fragment of C code under Unix on our
Sun network:

f()
{ system ("<title of this program> &");
  f(); }
main()
{ f() }

result: one completely trashed network, yours truly hung by the balls
out of the computer lab window and banned of the system for several weeks.
I almost said in passing to the System Administrator that O/S security isn't
what i
Xref: sparky comp.lang.c:11556 comp.lang.c++:11467
From: prechelt@i41s14.ira.uka.de (Lutz Prechelt)
Newsgroups: comp.lang.c,comp.lang.c++
Subject: exit many loops at once (was: Pascal vs C)
Date: 24 Jul 1992 12:33:18 GMT
Organization: University of Karlsruhe, FRG
Distribution: world
NNTP-Posting-Host: i41s14.ira.uka.de
Keywords: refinements, goto, leave, break

In article <1992Jul22.201454.26298@microsoft.com>, philco@microsoft.com (Phillip Cooper) writes:
|> In article <1992Jun13.220259.17547@beaver.cs.washington.edu> andrewb@lynx.cs.washington.edu (Andrew Berg) writes:
|> >ded@aplcen.apl.jhu.edu (nod sivad) writes:
|> >: >You can use "goto" e.g.
|> >: >
|> >: >{
|> >: >   for(...) {
|> >: >      for(...) {
|> >: >         if(...) goto exloop;
|> >: >      }
|> >: >   }
|> >: >exloop:
|> >: >}
|> >: >
|> >: >Sure, it is not a very good style, but is should work.

Hmm. The style can be improved by using refinements:
Put all three loops into one refinement called "threeloops" and replace
the goto by  
  leave `threeloops;
This is structured and is just a generalization of 
  break;

The C-Refine preprocessor that introduces refinements into C or C++
is available for anonymous ftp from
  iraun1.ira.uka.de [129.13.10.90]
  /pub/gnu/crefine.3.0.tar.Z

It also appeared on comp.sources.reviewed as v02i013 to v02i19
on July 15th, 1992

  Lutz

-- 
Lutz Prechelt   (email: prechelt@ira.uka.de)            | Whenever you 
Institut fuer Programmstrukturen und Datenorganisation  | complicate things,
Universitaet Karlsruhe;  D-7500 Karlsruhe 1;  Germany   | they get
(Voice: ++49/721/608-4317, FAX: ++49/721/694092)        | less simple.
Newsgroups: comp.lang.c,comp.lang.pascal
From: veerasam@utdallas.edu (Jeyakesavan Veerasamy)
Subject: Flexible array indexing in C (like Pascal)
Organization: Univ. of Texas at Dallas
Date: Fri, 31 Jul 1992 14:06:23 GMT


When translating Pascal programs to C, this tip may be helpful.

Flexible array indexing of pascal really gave lot of problems for me.
(It is common to see negative array indices in scientific pascal programs).
Following macro allocates the equavalent array in C.

It basically allocates the memory, returns the pointer
after adjusting it for index range.


/* Allocates array for which index value low to hi will be legal,
   Only requirement is, low < hi */

#define allocate(type,low,hi) \
	((type *) malloc ( (hi-low+1) * sizeof(type) ) - low)


/* Example usage */
main()	
{
	char *a;
	int *b;

	a = allocate( char, -200, -100 );
	b = allocate( int, 'a', 'z' );
	
	a[-200] = 'A';
	b['a'] = 2;
	b['z'] = 1;
}

With regards,
Jey.

 ----------------------------------------------------------------------
|  Mail: Jeyakesavan Veerasamy       M.S. Computer Science             |
|        2400 Waterview Pkwy #811    The University of Texas at Dallas |
|        Richardson TX 75080-2263    Email: veerasam@utdallas.edu      |
 ----------------------------------------------------------------------
From: mjs@hubcap.clemson.edu (M. J. Saltzman)
Newsgroups: comp.lang.c
Subject: Pointers outside of array boundary
Summary: Elaboration on FAQ answer wanted
Date: 28 Jul 92 18:09:45 GMT
Organization: Clemson University, Clemson SC

I am having an e-mail conversation with someone regarding the
_Numerical_Recipes_in_C_ practice of creating arrays with offset
indices.  The sample code in question is 

	float x = malloc(10*sizeof(float));
	--x;

which is supposed to give an array whose elements are addressed
as x[1]..x[10].  The FAQ points out that this is not strictly
conforming, since the decremented value of x no longer points
to a legitimate element of the allocated array.  My interlocutor
asks what could possibly go wrong if we only ever dereference 
x[1]..x[10], and I can only respond with hypothetical arguments
about the possibility of generating an invalid address.

My question is: Can anyone name an existing machine on which this code
could fail, or give a really convincing hypothetical argument why it
is a bad idea?  My interlocutor claims the criticism of this form is
legalistic, and not based on practical considerations.

Also, could someone quote the relevant part of the standard?  The
relevant portions of K&R2 cited in the FAQ don't seem to quite address
the issue head-on.

Thanks in advance.


-- 
		Matthew Saltzman
		Clemson University Math Sciences
		mjs@clemson.edu
From: wkaufman@us.oracle.com
Newsgroups: comp.lang.c
Date: 17 Jul 92 23:52 MDT
Subject: Re: (Help) dynamic use of sprintf ?
Nf-ID: #R:brself.711345285@hal:945470687:1992Jul17.195250.16522@oracle.us:1418735349:001:1925
Nf-From: us.oracle.com!wkaufman    Jul 17 23:52:00 1992


In article <brself.711345285@hal> brself@hal.gnu.ai.mit.edu (Ben Self) writes:
] 
] ...problems w/sprintf and buffer sizing...]
]
] I have tried many methods in the past, but am not happy with any yet tried.
] 
] Some of these include:
] 
]      . using the return value of fprintf () to a file pointer attached
]        to /dev/null with the same arg format that I pass to sprintf ()

    Oooh, icchh!  All the overhead of opening a useless file, writing to
the file every time, closing the file; the malloc()'s, free()'s and
system calls the stdio functions use.  This solution I'd *absolutely*
argue against.

]      . determining the size of integers by log10 or (in the event I
]        don't want to link to the math library) dividing by 10 until
]        it becomes fractional.

    It should be sufficient to add up the *maximum* sizes of all the
objects: for example, ints will be, at most, log10(INT_MAX) long.  On my
machine, that's about 11; so, at most, I'm only wasting about 10
bytes--certainly a fair price to pay if I avoid doing log10()'s.

]      . writing my own subset of sprintf () which takes care of this
]        problem [far more work than it is worth].

    That's actually not a bad idea, if you're only using a small subset
of the sprintf() options.  For example, writing one that takes only "%s"
and "%d" would be easy (well, as easy as any variadic function), and you
could handle all the realloc()'s for more memory and return a new
buffer.

    Naturally, this all depends on what you're using the buffer for: if
you're just going to print it out to a file or the screen, you'd do best
to avoid the whole issue and fprintf() this stuff directly.

                                           -- Bill K.

Bill Kaufman,          | "...all conscious species are plastic and
Corporate Lackey       |  all plastic species are conscious."
wkaufman@us.oracle.com |                     -- Yew-Kwang Ng
From: lingnau@math.uni-frankfurt.de (Anselm Lingnau)
Newsgroups: comp.lang.c
Subject: Re: Variant Records v. Unions
Date: 30 Jul 92 08:56:17 GMT
Distribution: world
Organization: University of Frankfurt/Main, Dept. of Mathematics

In article <1992Jul15.212536.3127@otago.ac.nz>, gpxpost@otago.ac.nz writes:
> [...]
> Solution 1.
> 
> #define base  u.pointer_or_file_or_set.base
> etc...
> 
> So lhsType->base expands to lhsType->u.pointer_or_file_or_set.base as
> required.  But now we're scared of clobbering any other variables called
> base.  So we need to use type name prefix thingies:
> 
> #define typ_base  u.pointer_or_file_or_set.base
> 
> and use lhsType->typ_base.  But I hate typ_ even more than u.stuff.base.
> [...]
> Solution 3.
> 
> This is where you fill in the blanks.  Anyone got any suggestions?

I often use `access macros' defined like

#define Kind(t)		((t)->kind)
#define PFSBase(t)	((t)->u.pointer_or_file_or_set.base)
#define PFSLow(t)	((t)->u.pointer_or_file_or_set.low)

Your example thus becomes

lhstype = translateExpr(node->lhs);
if (Kind(lhsType) == Pointer)
	return PFSBase(lhsType);
if (Kind(lhsType) == Array)
	CheckBounds(rhs, Index(lhsType));

A minor drawback is that the macros assume you will be accessing the struct
through a pointer, although it would be easy to define them with . in place
of -> and use *lhsType or some such when they are called. But that doesn't
look as neat, and normally you can make out beforehand whether you'll be
mostly using pointers or direct access. Actually this notation is similar
to the one Knuth uses for structures in TAoCP.

Anselm
--
Anselm Lingnau, Buchenweg 1, 6239 Eppstein| You see things, and you say `Why?'
lingnau@math.uni-frankfurt.de      Germany| But I dream things that never were,
University of Frankfurt, CompSci and Maths| and say `Why not?'  --- G. B. Shaw
Newsgroups: comp.lang.c
From: jarober@aplcen.apl.jhu.edu (DE Robertson james an 410-740-9172)
Subject: Re: Hungarian notation
Organization: Johns Hopkins University
Date: Mon, 20 Jul 92 22:44:24 GMT

aduncan@rhea.trl.OZ.AU (Allan Duncan) writes:


>This reliance on a compiler is no better than a journalist relying on a
>spelling and grammar checker.  It is getting very common now to see
>correctly spelled words of the correct part of speech that are clearly
>not the word that was intended.  Context gives you a clue as to what the
>correct word should have been, but in programming there is less context
>to work with.  Maybe the Hungarian Notation is intended to add context.

	You Have to rely on the compiler to some extent - otherwise, you
don't get code.  If you have an ANSI compliant C compiler, and your
prototype and your declaration disagree, you WILL get an error.  Naming
conventions are a good thing.  But blind trust in them is foollish.  
Hungarian is no better (or worse) than many other conventions.  What I 
find amusing is the religious intensity that seems to be attached to it -

"Use Hungarian - never make a mistake again !!"

Please.

jarober@aplcen.apl.jhu.edu
From: eric@prodigal.psych.rochester.edu (Eric Hansen)
Newsgroups: comp.lang.c
Subject: Re: freeware c libs
Date: 22 Jul 92 14:02:42 GMT
Organization: University of Rochester - Rochester, New York

In <0eP_ylm00WB2IrRFYN@andrew.cmu.edu> Nenad Ivezic <ni10+@andrew.cmu.edu> writes:

>Does anybody know of any good freeware c libraries with implementations of
>standard data types (hash tables, lists, ...) and sorting/searching algorithms.

There is an excellent book which provided examples of each of these types
of programs in both C and Pascal.  It is called the "Handbook of Algorithms
and Data Structures (in Pascal and C)", and is by G.H. Gonnet and 
R. Baeza-Yates.  The 2nd edition is (c) 1992 by Addison Wesley.  It
covers everything you would ever want to know (or used to know but can't
remember) about sorting, searching and data structures.

Eric Hansen
Center for Clinical Computing
Boston, MA
Xref: sparky comp.lang.c:11793 comp.sys.mac.programmer:13232
From: rsnyder@atl.ge.com (Bob Snyder)
Newsgroups: comp.lang.c,comp.sys.mac.programmer
Subject: Good introductory books on C
Date: 30 Jul 92 19:31:15 GMT
Followup-To: poster
Organization: GE Aerospace, Advanced Technology Labs

I'm looking for a good introductory book on learning C.  I've dabbled a bit
with it, and own K&R, but that really isn't a good tutorial text. :-)

I've done some work with other languages, and I'm not totally
computer-illiterate.

The environments I'd mist likely be working in would be UNIX and
Macintosh.  I have Think C for the Mac, and Sun and GNU's cc for UNIX.

Thanks,
Bob
-- 
Bob Snyder, Computing Services, GE Aerospace, Advanced Technology Labs
rsnyder@atl.ge.com, (609) 866-6672, FAX: (609) 866-6397, DialComm 8*777-6672
From: robertk@taoami.lerctr.org (Robert Kesterson)
Newsgroups: comp.lang.c
Subject: Re: Mixed Language Programming
Distribution: world
X-NewsSoftware: GRn 1.16e (7/4/92) by Mike Schwartz & Michael B. Smith
Date: 29 Jul 92 18:19:29 CDT
Organization: Not an Organization

In article <7123582903752@blotto> rolfb@blotto (Rolf Biesenbach) writes:
>
> 	I'm trying to link up a user-interface module written in MS QBasic 4.5 with
> 	12 stepper motor control modules written in MS C 6.0.
>
> 	I'm having trouble linking these modules becuase of duplicate definition
> 	errors in mlibce.lib, brun45.lib, and cm.lib. (Yes, I did use some TC++3.1
> 	functions.)
>
> 	If anyone has any suggestions on how to solve this problem, please reply.
>
> 	Thank you.

Make sure you put the basic modules first on the link command line,
and that you specify /NOE (No Extended Dictionary).  That should get it.

--

======================================================
 Robert Kesterson 	    robertk@taoami.lerctr.org
Newsgroups: comp.lang.c,comp.os.msdos.programmer
From: scs@adam.mit.edu (Steve Summit)
Subject: Re: Help with converting Borlandc peekb to Microsoft C equivalent
Followup-To: comp.os.msdos.programmer
Organization: none, at the moment
Date: Thu, 30 Jul 1992 19:48:36 GMT

In article <131818@lll-winken.LLNL.GOV>, 528010aisws7@llnl.gov writes:
> We are converting a  working Borland-C program to an equivalent Microsoft
> C++ program.  Is there a list of the corresponding function calls.
> In particular from Borlandc 's pokeb()  and peekb()  to the Microsoft C++
> equivalent

From the Jargon file:

:peek: n.,vt. (and {poke}) The commands in most microcomputer
   BASICs for directly accessing memory contents at an absolute
   address; often extended to mean the corresponding constructs in any
   {HLL} (peek reads memory, poke modifies it).  Much hacking on
   small, non-MMU micros consists of `peek'ing around memory, more
   or less at random, to find the location where the system keeps
   interesting stuff.  Long (and variably accurate) lists of such
   addresses for various computers circulate (see {{interrupt list,
   the}}).  The results of `poke's at these addresses may be highly
   useful, mildly amusing, useless but neat, or (most likely) total
   {lossage} (see {killer poke}).

   Since a {real operating system} provides useful, higher-level
   services for the tasks commonly performed with peeks and pokes on
   micros, and real languages tend not to encourage low-level memory
   groveling, a question like "How do I do a peek in C?" is
   diagnostic of the {newbie}.  (Of course, OS kernels often have to
   do exactly this; a real C hacker would unhesitatingly, if
   unportably, assign an absolute address to a pointer variable and
   indirect through it.)

					Steve Summit
					scs@adam.mit.edu
Newsgroups: comp.lang.c