HDTenEightyP/NetNews huggingface dataset:
From: jeffrey@squid.tram.com (Jeffrey L Bromberger)
Subject: Optimizing random number generator (was Re: Optimizing code for tests)
Organization: Tramway Unix Systems
Date: Sat, 15 Aug 1992 23:28:31 GMT
Keywords: optimizing numrec ran3

Well, I have to admit.  I am surprised by the sheer amount of advise I
have gotten from my last 2 posts.  Thanks to everyone!

My original query was "how to optimize conditional branches" in a C
program.  The landslide answer was:

You cannot - the compiler can do damn near anything it wants to.  If
you want to do this sort of micro-optim work, go to assembler :-)

OK, I can live with that.  The second suggestion was to work on my
biggest time hog, the random number generator.  It runs pretty fast,
in my opinion, but takes up most of the time because of the sheer
number of times it's called.  I decided to do a profiled run last
night, and here's the prof(1) report


 %Time Seconds Cumsecs    #Calls   msec/call  Name
  41.9 7555.50 7555.50  78453355      0.0963  generate

Again, the random generator was first on the list.  This was a small
run of the simulator, nowhere near the actual size.  I do think that
prof is broken, due to the small number of calls (78 million) - I was
expecting a bit more than this.  BTW: this was run on a AT&T 3B2/400,
compiled with a good C compiler that makes use of the floating point
unit, and optimizes well.  That msec is probably milliseconds - AT&T
System V manuals don't clearly say.

So, about the generator.  It's the "ran3" generator taken from the
text _Numerical_Recipes_in_C_.  This is supposed to be derived from on
of Knuth's generators.  The whole thing works in int math, with a bit
in long integers.  It returns a float, but the division is the last
thing done.  I guess I could have it return a long and divide it
later, but I felt that having the division internal to the generator
was cleaner.

Already, I have been given the suggestion to "inline" the code, and I
will be trying that.  Are there any other suggestions that might be
helpful?  Are there better generators that this one?  Just looking for
one that is fast, has a high period, and gives an flat distribution of
numbers (not a normal distribution).

Once again, thanks in advance for any tips.

j
-- 
Jeffrey L. Bromberger ------- System Manager ------- Tramway Unix Systems
jeffrey@squid.tram.com      Anywhere!{van-bc,limbic,icus}!tram!jeffrey
Newsgroups: comp.lang.c
From: clennox@vaxeline.ftp.com (Systems Anarchist)
Subject: Re: Pointer/address reluctance
Organization: FTP Software, Inc., Wakefield, MA
Date: Mon, 17 Aug 1992 15:55:53 GMT

In article <l8ojbqINN900@exodus.Eng.Sun.COM> linden@positive.Eng.Sun.COM (Peter van der Linden) writes:
>I take the point that some folks like to distinguish 
>between pointers and addresses because of unusual hardware
>that may include capability or offset bits.  

This is not simply a matter of pendantry.  On the PDP-10, an address
is 18 bits long.  A byte pointer is 36 bits long.  They are two
completely different objects.  Of course, if you never use 'address'
when you really mean 'pointer,' you need never care about
architectural details like that.

>However, Joe put his finger on the nub of this by pointing
>out (heh!) that we may simply expand our informal concept 
>of "address" to include these as desired.

You are perfectly free to redefine 'address' to mean 'pointer.'  In
that case, the issue of whether a pointer is an address becomes moot.
But I'm not sure what exactly you gain from that, besides the ability
to have two words with the same meaning.  The word "address" already
has a perfectly useful meaning in hardware.

-- 
%SYSTEM-F-ANARCHISM, the operating system has been overthrown
From: walterm@hpwrce.mayfield.hp.com (Walter Murray)
Date: Wed, 19 Aug 1992 16:24:08 GMT
Subject: Re: How many malloc's can I use?
Organization: the HP Mtn.View Resp. Cntr.
Newsgroups: comp.lang.c

In comp.lang.c, elias@proxxi.se (Elias M}rtensson (proxxi)) writes:

> And does ANSI C specify that largest block of memory that can be
> malloc'ed?

For maximally portable code, I would avoid requesting more than
32767 bytes in a call to malloc, because that is the maximum size
of an object in a strictly conforming program.  (ANSI 2.2.4.1, 1.7)

Walter Murray
-------------
Newsgroups: comp.lang.c
From: wolf@hubcap.clemson.edu (Randy Martin)
Subject: String hashing algorithms
Keywords: hashing
Organization: Clemson University
Date: Mon, 17 Aug 1992 13:31:17 GMT

Does anyone have any string hashing algorithms that are very fast and
produce few collisions?  

Any help would be greatly appreciated!


-- 

---
Randy Martin
wolf@hubcap.clemson.edu
From: tiok_ks@tac.fi
Newsgroups: comp.lang.c
Subject: Re: Using ANSI.SYS codes from C?  (Turbo)
Date: 19 Aug 92 10:51:37 GMT
Followup-To: comp.lang.c
Organization: City of Tampere

In article <1992Aug18.111356@shovel.Prime.COM>
tim@shovel.Prime.COM (Tim Cantin) writes:
> esc[xm		set color x where colors are:
> 		foreground:	background:
> 		30 black	40 black
> 		^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^___darn, I can't remember them!
> 						it's the same as the resistor
> 						code table if you know that! :)~

> p.s.
> 	If anyone knows those color codes, feel free to post them! *grin*

I don't think it's the same... Resistors have 10 different colours,
order of which I'm not sure of, but according to the Programmer's PC
Sourcebook there are only 8 ANSI colours:

text	bkgr.	colour
----	-----	------
30	40	black
31	41	red
32	42	green
33	43	yellow
34	44	blue
35	45	magenta
36	46	cyan
37	47	white

--------------------------------
Kimmo Surakka     tiok_ks@tac.fi
Newsgroups: comp.lang.c
From: Doug.Schales@sc.tamu.edu (Douglas Lee Schales)
Subject: Re: Convert float to a string ?
Organization: Texas A&M University Supercomputer Center
	<1992Aug20.172112.1564@tin.monsanto.com>
Date: Thu, 20 Aug 1992 21:31:02 GMT

In article <1992Aug20.172112.1564@tin.monsanto.com> bcschu@skws02.monsanto.com (Brett Schultz) writes:
>   : 
>   : 	Are you sure you need a '\0' here............???
>   : 
>   : 	Prem!  (I guess I should've written a test program to find out, )   
>   : 	       ( rather than posting this..........                     )
>
>   No, I'm not sure if one NEEDS a \0 there, but it surely doesn't hurt to put
>   one there, now you KNOW that your string is null terminated.
>
>   Let me know if sprintf puts one there anyway, I wasn't sure.
>

Uhhhh... if you stop and think about this for just a weeee bit, you'll
realize the answer is that you don't need one... 

Doug.
--
--
Douglas Lee Schales               Internet:  Doug.Schales@sc.tamu.edu
Texas A&M University                Bitnet:  d1s8027@tamsumma
Supercomputer Center                
Newsgroups: comp.lang.c
From: K_LEPA@unhh.unh.edu (Kristen   Lepa)
Subject: Harvest C problems...
Organization: University of New Hampshire
Date: Thu, 13 Aug 1992 01:35:53 GMT
X-News-Reader: VMS NEWS 1.12

Well, after getting my account on UNH's mainframe quintupled to download
it, I finally got Harvest C onto my mac LC (after several hours).  The
one problem is that whenever I try to run a program, or do anything for
that matter, I get an unimplemented trap error.  Does anyone know what this
is and how I can solve it?  I have a mac LC with 4 meg of ram, several inits
which I can list if needed, and I have a software FPU.  I haven't contacted
the author yet, because I didn't want to bother him yet without having first
paid for (or tried) the program.

	Thanks for any help,
		-Kristen

k_lepa@unhh.unh.edu
Newsgroups: comp.lang.c
From: ceblair@ux1.cso.uiuc.edu (Charles Blair)
Subject: CWEB run on DOS machine?
Organization: University of Illinois at Urbana
Date: Sun, 23 Aug 1992 14:54:09 GMT

   Has anyone done the modifications of the literate programming system CWEB
(Levy & Knuth) to make it run on DOS?  I have been trying to get it to work
with Turbo C 2.0.  I think I will be able to get CTANGLE to work after I
change the system dependent sections, but I am getting some puzzling error
messages from CWEAVE (I have the uneasy suspicion the program may be too
large to handle, even with Turbo C's TCC compiler).

   I would be delighted if somebody else has already done this stuff, so
I don't have to!
Newsgroups: comp.lang.c
From: sasghm@theseus.unx.sas.com (Gary Merrill)
Subject: Re: Is "...", instead of ",..." legal ?
Originator: sasghm@theseus.unx.sas.com
Date: Thu, 13 Aug 1992 17:31:30 GMT
Organization: SAS Institute Inc.
Keywords: variable arguments


In article <1992Aug13.002717.18476@megadata.mega.oz.au>, scott@megadata.mega.oz.au (Scott Humphreys) writes:
|> In various books describing the expansion to ANSI-C,
|> one of the differences is described as the inclusion
|> of the ",..." operator for function prototypes
|> [ meaning that a variable number of arguments follow-
|>   e.g. int printf (const char *, ...);  ]
|> 
|> My question is: is this legal : int foo (...);
|> 
|> That is - can I legally declare a function 
|> with none or many arguments, or does it HAVE to have
|> at least one argument.
|> 
|> This came up because gcc version 2.2.2 let me do it,
|> but gave a warning when used with the -pedantic option.
|> Another tool I used (gnu GCT version 1.3) bombed on this construct.

This is non-ANSI, but some compilers permit it.  (Generally what
it really means is "Here's a prototype, so don't annoy me with
a message about a missing prototype for this function.  But I
won't give you a clue about what the parameters are, so don't even
try to check them.")
-- 
Gary H. Merrill  [Principal Systems Developer, C Compiler Development]
SAS Institute Inc. / SAS Campus Dr. / Cary, NC  27513 / (919) 677-8000
sasghm@theseus.unx.sas.com ... !mcnc!sas!sasghm
Newsgroups: comp.lang.c
From: svenning@cc.curtin.edu.au
Subject: Still seeking C++ libraries!
Organization: Curtin University of Technology
Date: Tue, 18 Aug 1992 07:22:23 GMT

Hello,

     Regarding my plea for information about the location of C/C++ libraries
.....well....I'm still looking...

I would be grateful if anyone could put me onto any sources of libraries on
the net or otherwise, as I need help in finishing my current project i.e.
a database system (specifically for use by real estate firms for property 
management!)...any GUI routines or search/sort algorithms would be helpful.

                                                  Regards,
                                                         Todd Venning

                        e-mail: svenning@cc.curtin.edu.au
From: jos@and.nl (Jos Horsmeier)
Newsgroups: comp.lang.c
Subject: Re: Sort help needed
Date: 13 Aug 92 08:32:07 GMT
Organization: AND Software BV Rotterdam

In article <1992Aug12.154130.1@ducvax.auburn.edu> swanger@ducvax.auburn.edu writes:
|I am writing a program in C.  I have an array of character strings that
|I want to sort (I dynamically allocate the "array" with a series of
|calloc statements, so to the purist I suppose it isn't really an array,
|I just pretend like it is one).  The array usually contains around 1800
|strings of 512 characters each.  I sort the array (sort the pointers
|actually) with the following sort routine (on a SUN IPC Sparcstation)
|and it usually takes 8 to 10 seconds to finish. [ and this is too slow ... ] 

|------------------------------------------------------------------------
|void sort_strings(strings, num)
|char *strings[];
|int num;
|{
  [ bubble sort algorithm deleted ... ]
|}

I strongly suggest _not_ to use this algorithm. It's dead slow, it
takes up O(n^2) loop iterations to sort the strings. In your example,
sorting 1800 strings, the innermost instructions (inside both loops)
are executed n*(n-1)/2= 1619100 times.

Have a look at the qsort function, it's in you lib somewhere. If you can't
use that function for some reason (I don't see why,) may I suggest an
alternative algorithm: heap sort. It's a bit slower than quick sort,
but it's a very stable algorithm. i.e. quicksort might degenerate to
O(n^2) behavior in the worst case, but heap sort is stable at O(n*log(n)).
Both algortihms sort the array `in place', they don't need additional
storage. An rudimentary implementation of the heap sort looks something
like this:

void heap_sort(strings, num)
char *strings[];
int  num;
{
int n;

for (n= num/2; n >= 0; n--)		/* Build the inital heap */
   heapify(strings, n, num);

for (n= 0; n < num; n++) {		/* Swap root and last element */
   swap(strings, 0, num-1-n);	
   heapify(strings, 0, num-1-n);	/* Build new (smaller) heap */
}

}

void heapify(strings, n, num) 
char *strings[];
int n;					/* Position in the heap */	
int num;				/* Number of strings */
{
int l, r;				/* Left and right sons */

for(; (l= 2*n+1) < num;) {		/* Loop while left son present */
   if ((r= l+1) < num)			/* Right son present? */
      if (strcmp(strings[l],
		 strings[r] < 0)	/* Right son > left son */		
         l= r;
   if (strcmp(strings[n], 
	      strings[l]) >= 0)		/* Already a heap here */
      break;

   swap(strings, n, l);			/* Swap root with son */

   n= l;				/* Descent this sub tree */
}

}

I hope this is of any help to you,

kind regards,

Jos aka jos@and.nl
Newsgroups: comp.lang.c
From: jsteele@netcom.com (John Steele)
Subject: How to implement a vsscanf (MSC and *nix)
Date: Sat, 22 Aug 92 08:06:49 GMT
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
Keywords: vsscanf,MSC

I haven't seen the FAQ lately (if it contains any info on this)...

I'm looking to implement a vsscanf() function similar to Borlands under
MSC 5.1/6.0/7.0 and *nix C.  Anyone have any pointers?

Please respond email, and I'll summarize if requested.

Thanks,
  John
-- 
#include <disclaimer.h>			/* route all flames to /dev/null  */
/**************************************************************************/
/*   Systems Analyst      | John Steele     email: jsteele@netcom.com     */
/* Video Business Systems |                                               */
/*   1-800-255-3088       |    Most people spell COBOLSUX incorrectly...  */
/**************************************************************************/
Xref: sparky comp.lang.c:12568 comp.lang.c++:12636 gnu.g++.help:1140 gnu.gcc.help:1954 gnu.misc.discuss:2742
From: ms@lehre11.informatik.Uni-Bremen.DE (Martin Schroeder)
Newsgroups: comp.lang.c,comp.lang.c++,gnu.g++.help,gnu.gcc.help,gnu.misc.discuss
Subject: Experiences with modifying gcc/g++
Date: 20 Aug 92 13:59:54 GMT
Organization: Universitaet Bremen

Has anybody experiences with modifying gcc/g++ for your own purposes (e.g. a
crossreferencer)?

------------------------------------------------------------------------------
Martin Schr"oder		EMail:  ms@informatik.Uni-Bremen.de
FB 3, Informatik		UUCP:   unido!ubrinf!ms
Univ. Bremen			
Xref: sparky comp.lang.c:12688 comp.sys.sun.misc:3861
From: chuckb@milton.u.washington.edu (Chuck Bass)
Newsgroups: comp.lang.c,comp.sys.sun.misc
Subject: Re: How to use the same file of structs on PC and Sun?
Date: 24 Aug 92 02:53:11 GMT
Article-I.D.: milton.chuckb.714624791
Organization: University of Washington

As has been previously stated having portable binary files is
inherently not portable.  Big endian/Little endian, byte
alignment, format of floats and size of ints, longs and shorts
are a sample of what you have to contend with.

Unfortunately, the portable solution is to use ASCII files and
read  your files as text using fscanf or some such mechanism.
This is not an ideal solution if file size is of any concern.
  
Sorry if this isn't the answer that you wanted...


Chuck Bass
College of Forest Systems Engineering
University of Washington
chuckb@u.washington.edu
Newsgroups: comp.lang.c
From: edc323usft@vx24.cc.monash.edu.au
Subject: no stdlib.h and 150 digit numbers
Organization: Computer Centre, Monash University, Australia
Date: Wed, 19 Aug 1992 03:22:38 GMT

G'Day

I'm tring to write an RSA encryption algorithim, and implement it using
NASI C, however, much to my surprise neither the Unix machine nor the
VMS machine I am using have a stdlib.h file for use with the compiler. 
This is needless to say a small problem.  Does anyone have any ideas??

Also, for the same project I need to manipulate integers with between
150 - 200 digits, I have had some help in this problem, but any other
advise is more than welcome.

Travis
Newsgroups: comp.lang.c
From: davisonj@bnr.ca (John Davison)
Subject: Re: C++ for windows. A few questions
Organization: Bell-Northern Research, Richardson, Tx.
Date: Wed, 19 Aug 1992 17:16:33 GMT

In article <1992Aug19.155127.24116@vela.acs.oakland.edu> jmwojtal@vela.acs.oakland.edu (Wojo) writes:
>The company I work for is expanding their computer system, and plans to use
>DecWindows.  We're looking into getting C++, an object oriented code that can
>not only run windows, but create them as well.

        I don't believe you.


-- 
NOTE: I CAN'T SEND/RECEIVE E-MAIL HERE!!!  Use --> davisonj@ecn.purdue.edu <--
      During (roughly) August 20-25, I will be in transit.  Please be patient.
      The opinions and other information contained herein are not necessarily
      representative of Northern Telecom or any of its subsidiaries. 
Newsgroups: comp.lang.c
From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
Subject: Re: How many malloc's can I use?
Organization: Computer Science, University of Melbourne, Australia
Date: Tue, 18 Aug 1992 11:27:02 GMT

elias@proxxi.se (Elias M}rtensson (proxxi)) writes:

>Does ANSI C specify the maximum number of malloc calls that can safely
>be made? Can I do a couple of thousand malloc's and still count on
>that everything will work fine? I am not interested in any
>descriptions of the MS-DOS limitations or anything like that. I just
>want to know what ANSI C says.
>
>And does ANSI C specify that largest block of memory that can be
>malloc'ed?

I am fairly sure that the following would be a ANSI-conforming implementation
for malloc:

void *malloc(size_t size) {
	errno = E_THIS_SYSTEM_DOESNT_HAVE_DYNAMIC_ALLOCATION;
	return 0;
}

In other words, I fairly ANSI does not make any guarantees as to the amount
of memory that can be allocated with malloc. The only constraint is that if
for whatever reason it cannot allocate the desired amount, it must return
a null pointer after setting errno to an appropriate value.

-- 
Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
This .signature VIRUS is a self-referential statement that is true - but 
you will only be able to consistently believe it if you copy it to your own
.signature file!
From: den@cci632.cci.com (Dennis J. Buttery)
Newsgroups: comp.lang.c
Subject: Re: Convert float to a string ?
Date: 20 Aug 92 12:18:09 GMT
Organization: [Computer Consoles, Inc., Rochester, NY

In article <16848E30C.KSZ@VM.NRC.CA> KSZ@VM.NRC.CA writes:
>Suppose I have a float a=12.4567, how can I convert it into a string including
>8 characters? i.e. What I want is
>                 char *b="12.34567";
>One way may be writing the float into a temp file then load it as a string.

	I believe that many compilers have an ftoa() function which works along the lines of atoi(), and itoa().  I also seem to remember seeing a atof() counterpart around which would convert an ascii string into a float value.  These may be part of a floating-point library or such.

	I don't program using floating-point operations very often so I`m a little rusty on this one. :)
 
                                          -DJB-
Newsgroups: comp.lang.c
From: tomg@stud.cs.uit.no (Tom Grydeland)
Subject: Re: Using super VGA in C?
Followup-To: alt.flame
Organization: University of Tromsoe
Date: Sat, 22 Aug 1992 20:01:16 GMT

Warning: Flames follow

In article <1992Aug19.121930.4804@ecl.psu.edu>, l1z@ecl.psu.edu writes:
|> Please help! I want to be able to use high-resolution (1024 X 768 X 256 color)
|> in my C codes. But I don't know how to set the video mode. I am using the
|> MicroSoft C 5.0 on a PC. the graph.h file only support the standard VGA modes.
|> Can any one tell me how I can use super VGA modes? Thanks in advance.

You'll probably get plenty of help in any of these groups:

comp.sys.ibm.pc
comp.sys.ibm.pc.hardware
comp.sys.ibm.pc.misc
comp.sys.ibm.pc.programmer
comp.ibm.pc.hardware


And that goes for all the Borland C/C++, MS C and *any* other hardware/vendor
specific questions; You'll get more help on a *.<machine>.* group than here
in comp.lang.c. This group is *not* for machine/vendor/hardware specific
questions/answers, please keep them out of comp.lang.c.

|> Joe

-- 
//Tom Grydeland(tomg@stud.cs.uit.no)._._._._._._._._._._._._._._._._._._._._._
|A._| . . ._| | |_._._. . ._|_._._._._. ._|_. ._ _._. ._| | . ._|_. | . ._._. |
| ._|_| |_. | | | | ._._|_. |_._. . |_. | | | ._._| |_._._._| | ._. ._| . . |_|
|_._._._._|_._._._._._._|_._._._._|_._._._._._._._._._._._._|_._._|_|_._|_|_.B|
Newsgroups: comp.lang.c
From: pynq@quads.uchicago.edu (George Jetson)
Subject: Sorting (continued)
Summary: Looking for best sort algorithm
Reply-To: pynq@midway.uchicago.edu
Organization: D. J. Dougherty & Associates
Date: Sat, 15 Aug 1992 13:58:36 GMT

(I know this doesn't really belong in comp.lang.c, being as it is an
algorithm question.  Please advise as to better newsgroup(s))

I am trying to design an in-memory sort (no, this is not a class project)
(I'm too old for that crap..., but seriously folks...) and have narrowed
it down to 3 possible algorithms.  Note: It is a requirement that the
design not place any limits on the input (i.e., record length or number
of records)  Which do you think would be the best/most efficient?

	1) Build up a data structure along the lines of:

		struct thing {char *key,*text;}
	
	   where the things are malloc'd in blocks and you periodically
	   realloc them, so as to keep a contiguous block of memory.
	   (I am assuming that realloc does recopy the data if it needs
	   to move the block - this re-copying could be costly)

	   After reading all the input, call the qsort() intrinsic.

	2) Build up a linked list, along the lines of:

		struct thing {char *key,*text; struct thing *next;}
	
	   Now, you don't have to do any reallocs, but at the end, you
	   have to traverse the list, and build an array of pointers to
	   the things and qsort that.  (You keep a count on the first
	   pass so that you known how big to calloc the array of
	   pointers)

	3) Build a binary tree in the first pass, then simply print the
	   tree in traversal order.

Thanks for any and all help.  These are essentially the choices, but
feel free to point out any errors in my analysis.


	(I need to re-read Knuth...)

************************************************************************
Please don't drink the battery acid, it tastes bad and will hurt you.
Also, don't bite the tyres, especially when the bike is moving.
(Our lawyers made us put this in this manual.)

	- pynq@quads.uchicago.edu, who is still costing the net
	  hundreds, if not thousands, of dollars, every time he posts -
************************************************************************
From: robert@triton.jpl.nasa.gov (Robert Angelino)
Newsgroups: comp.lang.c
Subject: Looking for Polynomial Least-Squares Curve fit func. in C.
Date: 18 Aug 92 22:32:04 GMT
Reply-To: robert@triton.Jpl.Nasa.Gov
Organization: Jet Propulsion Laboratory, Pasadena CA

C gurus,
	I'm looking for a function that determines a polynomial
that fits a given discrete set of data.  Any help is
appreciated.  BTW--It has to be in C.  I can't stand fortran.

thanks


-robert