HDTenEightyP/NetNews huggingface dataset:
From: jon@jonlab.UUCP (Jon LaBadie)
Subject: Re: a question about if and case
Date: Thu, 24 Dec 1992 09:21:19 GMT
Organization: JG Computing

In article <1gi6poINN3lv@nz12.rz.uni-karlsruhe.de> "hans friedrich steffani" <GM08@DKAUNI2.BITNET> writes:
>
>i have something like
>
Query about efficient "if-elseif-" vs switch code is --- Deleted

I recall an article in UNIX World or UNIX Review in about their third
year (circa 1986) that addressed this question for then current compilers.

The conclusions (as I remember them) were that there was a cross-over
point at about 3 to 6 "cases".  Fewer than 4, if-else-if was more
efficient.  More than 5, switch/case was more efficient.  This cross
over point was influenced by the nature of the "cases".  A group of
sequential cases favored the switch solution.  Other considerations
were also noted.

Based on that article, I would say branch statements with a large
number of destinations should use a switch/case construct, those
with a few destinations should use an if/else-if construct.

The above comment is based on an efficiency viewpoint.  Should you
feel one construct is more readable than the other, certainly go
for your preference.

Change only when performance has become an issue and you note,
through profiling, that the multi-way branch is a problem.

-- 
Jon LaBadie
princeton!jonlab!jon
Newsgroups: comp.lang.c
From: dirsolns@world.std.com (Bernard Farrell)
Subject: Re: Arrays with variable dimensions?
Organization: Directed Solutions Group
X-Newsreader: Tin 1.1 PL3
Date: Thu, 31 Dec 1992 16:26:04 GMT

darcy@druid.uucp (D'Arcy J.M. Cain) writes:
: dirsolns@world.std.com (Bernard Farrell) writes:
: >ah017@yfn.ysu.edu (John B. Lee) writes:
: >: Is it possible to create an array that would change size according
: >: to user input?
: >float fl_arr[] = NULL;   /*  This is actually a float * -- no space  */
: 
: You didn't even try this did you?  This actually does assign space to an
: array.  I don't know what your compiler does with the "= NULL" but assuming
: it even accepts it (mine doesn't) it certainly doesn't do what you think it
: does.  If you want a float * why didn't you just declare that:
: 
: float *fl_arr = NULL;
: 

D'Arcy,

First of all, the approach I've outlined works for me on a number
of machines.  Second, ff I'm going to treat the pointer as an array,
I'd rather make this OBVIOUS in the declaration, even if the variable
name does help.

I'd be interested to know the kind of machine you compiled this
on, the ones I've done this before on may not be very ANSI compliant.
-- 
|----------------------------------------------------------|
|      Bernard Farrell      |   Directed Solutions Group   |
|----------------------------------------------------------|
|   dirsolns@world.std.com  |       (617) 429-2306         |
Newsgroups: comp.lang.c
From: nick@osf.org (Nick Dokos)
Subject: Re: Query : Algorithm book
Organization: Open Software Foundation
Distribution: usa
Date: 23 Dec 92 16:57:51 GMT

bandy@aplcomm.jhuapl.edu (Mike Bandy) writes:
   hahn@csd4.csd.uwm.edu (David James Hahn) writes:

   >I'm looking for a good book of algorithms with C code- sorting,
   >graph algorithms,  etc... Can anyone recommend one?  I'm not looking
   >for an instructional book, but  more  of a "handbook."   

   I like the "Numerical Recipes" text.  The one I use is based on Fortran,
   but I understand there is a C version.

But apart from sorting, it covers ONLY numerical algorithms. I like Sedgewick's
book (some people hate it however - browse before buying).

--
Nick Dokos	nick@osf.org	
OSF Systems Engineering

Member of the League for Programming Freedom - write to lpf@uunet.uu.net
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.lang.c
Subject: Re: [FAQ] size of executables ?
Date: 3 Jan 93 21:22:35 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <93003.004225RVK@psuvm.psu.edu>, RVK@psuvm writes:
>How does one compile a c program so that the size of the
>executable is as small as possible.

Most compilers have various switches that effect the size of the executable
in various ways.  For instance, you may have switches to include information
for debugging, or profiling.  Debugging information, in particular, can
greatly inflate the size of the executable.  It doesn't really matter when
you're trying to find a bug, but you should be sure that they're turned
off when you're ready to put it into common use.

Additionally, compilers typically have a switch to turn on various
optimization routines, which typically result in a smaller as well as
faster executable.

There may also be switches that effect such things as the size of integers,
which can also be used to reduce the size of the executable (but watch out--
there's a lot of code out there that assume sizeof(int) == sizeof(int *)...)

Beyond that, about all you can do is try different compilers, which tend to
vary quite a bit on the quality of code produced.

>I noticed that even a
>trivial program like Hello.c  produces a huge executable,

I'm not sure what you consider "huge"...

  #include <stdio.h>
  main() { puts("Hello, world") ; }

produces an executable of 24576 bytes in size on my machine (a Sun 4...)
In my experience, programs compiled on a Sun tend to be larger than elsewhere,
but not (completely) unreasonably so... 24+K might seem large for a program
that simply sends a 13 byte string to the standard output, but as you
surmize:

>perhaps due to the include files stdio.h etc.

This isn't quite correct... if you look at the contents of <stdio.h>, you'll
see externs for lots of functions.  The code for these functions lives in
the "standard library", which typically gets linked in to every program you
compile.  Theoretically, there's no reason why the whole library has to be
linked into your program when you only use a tiny piece of it... but it's
much easier to do it that way, and given the fact that disk space and memory
is fairly cheap, there's little motivation to do it just to save a few K off
of a few small programs.

-- 
Dave Schaumann			dave@cs.arizona.edu
From: jcu@dec5.ulb.ac.be (Jean-Christophe Ury)
Newsgroups: comp.lang.c
Subject: Access aliases ????
Date: 22 Dec 92 09:55:15 GMT
Distribution: world
Organization: Free University Brussels  - Belgium -  Department of Molecular Biology



It may seems stupid but I ask you anyway,

I use ULTRIX V4.3.
I 've  some aliases defined in my shell.I would access these aliases via
a C program. Is it possible.

Please answer me.  Thanx.


email : jcu@134.184.80.3
From: arlet@einstein.et.tudelft.nl (Arlet Ottens)
Newsgroups: comp.lang.c
Subject: WANTED: Fast addition for 64-bits integers in C
Date: 31 Dec 92 14:23:37 GMT
Organization: Delft University of Technology, Dept. of Electrical Engineering

Hello world,

I want to make an implementation of 64-bit integers in C, using
a pair of 32-bit integers.

What is the most optimal way to implement an addition and a subtraction
function in C for these integers ? 

Consider the cost of normal integer operations, like + - << >> & ^ | 
to be 1 processor cycle.

Please reply by E-mail, I'll post a summary if I get some "me-too's".
Newsgroups: comp.lang.c
From: afoiani@nmsu.edu (Anthony Foiani)
Subject: Re: QUESTION: TRICKS USING THE ? : OPERATOR
Organization: NMSU Computer Science
	<1992Dec23.001617.9462@kpc.com>
Date: Tue, 29 Dec 1992 04:01:42 GMT


In much the same vein, one of my favorites goes something like this:

   int a, b, c;

   *(c?&a:&b) = val;

Not that this is really "recomended".  With one notable exception*,
your goal should always be the most readable code; if an "if"
statement is more readable than a nested arithmatic conditional, the I
recommend the "if" statement.  IMHO, of course.

* The IOCCC, of course!

Tony
--
Tony Foiani  a.k.a. Tkil  (afoiani@nmsu.edu) or (tkil@acca.nmsu.edu)
Supporting:  Unix / DOS / VMS / Macintosh / "What's this?"
   Current favorite song: "Take To The Sky", Tori Amos, _Winter_ [CD5]
From: rdorich@jade.tufts.edu (Rob)
Newsgroups: comp.lang.c
Subject: Re: finding prime numebrs
Date: 22 Dec 92 04:57:50 GMT
Distribution: wold
Organization: Tufts University - Medford, MA

>	Since some one else had something to prove in this newsgroup,
>I'm going to post this (do we have/need a group gen.nums.proves?).
>Ok, so here it goes:
>
>	For any prime number, if we represent it in base 3, and then
>get the addition of all the digits, I claim that:
>
>	1.-	If the sum is even, then it is not a prime.
>
>	2.- 	If it is odd:
>			It is either prime.	
>			or a multiple of another lower prime.
			^^^^^
			Oops, I meant the multiplicand of 2 other
prime numbers.

Rob



--
-------------------------------------------------------------------------------
Roberto Dorich		 |           /~~  \ /  ~~/~~ /~~/  /~~  /|  /    /~~
			 |    SKI   /--    X    /   /__/  /--  / |/ |   /--
Electrical Engineering	 |         /__    / \  /   /\    /__  /     |  /__
rdorich@jade.tufts.edu	 |  Tufts University, College of Engineering.
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
Roberto Dorich		 |           /~~  \ /  ~~/~~ /~~/  /~~  /|  /    /~~
			 |    SKI   /--    X    /   /__/  /--  / |/ |   /--
Electrical Engineering	 |         /__    / \  /   /\    /__  /     |  /__
rdorich@jade.tufts.edu	 |  Tufts University, College of Engineering.
-------------------------------------------------------------------------------
From: wangbs @casd1.iie.ncku
Newsgroups: comp.lang.c
Subject: Find files of a directory in UNIX
Date: 23 Dec 92 07:34:00 GMT
Organization: CASD Lab.


   Hi, all :
       In UNIX, how can I program to find all files in a directory ?  Since
   I am not familar in C, It is better having example...
   
        Thanks for any response & happy new year !!!!
                                
                                  wangbs@casd1.iie.ncku.edu.tw
From: kdq@quest.UUCP (Kevin D. Quitt)
Newsgroups: comp.lang.c
Subject: Re: speed?  double vs. float.  math.h??
Date: Sat, 26 Dec 92 11:31:48 PST
Reply-To: srhqla!quest!kdq
Organization: Job quest  (805) 251-8210,  So Cal: (800) 400-8210

c60b-3hu@web-3c.berkeley.edu (Paul Hsu) writes:

> 
>      I'm currently writing a C program where it needs to do lots and lots of
> trig calculations.  But I would like the program to run really really fast.
> So I'm concerned about the speed at which the calculations are carried out.
> Trying to make the program run fast, I would like to have only float 
> variables, instead of doubles, in my program.  But in the standard math 
> library, all the functions take in arguments and return values in the type 
> double.  So, what should I do?  First of all, should I even be concerned 
> about the speed difference between doing calculations in float and doing the
> calculations in doubles?  If yes, how should I go about in making the math 
> functions to accept and return floats?  Casting them won't help....  it'll 
> only take more time in the type conversion.  Any suggestion?

    It depends on your machine.  If your machine uses IEEE format
floating point, and has hardware to do the calculations, then the
internal calculation format is probably always double, if not long
double.  (Motorola's FPUs use the 96bit long double format.  Intel's
FPUs use double format).  You might want to benchmark your program
per:

typdef float	FP;
 and define all your floats as type FP.  Next time, use:

typedef double	FP;


 _
Kevin D. Quitt      96.37% of all statistics are made up.     srhqla!quest!kdq
Xref: sparky comp.lang.c:18792 comp.programming:3354
From: slahiri@jade.tufts.edu (Sandip Lahiri)
Newsgroups: comp.lang.c,comp.programming
Subject: Re: B-Tree Algos/programs in C needed urgently.
Date: 22 Dec 92 20:19:20 GMT
Organization: Tufts University - Medford, MA

In article <1992Dec22.201110.29332@news.tufts.edu> slahiri@jade.tufts.edu (Sandip Lahiri) writes:
>
>The subject line says it all. Any help/pointers regarding good books/ftp
>sites/etc. would be sincerely appreciated. Thanx in advance and have a
>merry christmas a great new year.
>
>-Sandip

Oops, made a mistake in my original posting. The last line should read
as
Thanx in advance, have a Merry Christmas and a Happy New Year.

-Sandip
From: jungjk@unixg.ubc.ca (Jinki Jung)
Newsgroups: comp.lang.c
Subject: Think C 4.0 and Debugger at System 7
Date: 4 Jan 1993 05:25:39 GMT
Organization: University of British Columbia, Vancouver, B.C., Canada
NNTP-Posting-Host: unixg.ubc.ca


	Hi,

		I try to use Think C with Debugger function on. 
	Every time I RUN a project, the screen get frozen in the middle of
	processing. According to the manual, using Debugging function requires
	at least 2MB of memory. I have total 4 MB of memory and use System 7.
	I wander why this is so. 

		If this is not good place to ask, I would appreciate if
	anyone point me a proper newsgroup.

 	Jung JK (jungjk@unixg.ubc.ca) 

	

  


Newsgroups: comp.lang.c
From: isc@panix.com (David Koosis)
Subject: Re: Yacc/ BNF Form / HELP!
Date: Mon, 28 Dec 1992 15:00:46 GMT
Organization: PANIX Public Access Unix, NYC

In <Dec.27.14.34.23.1992.17980@romulus.rutgers.edu> adrian@romulus.rutgers.edu (Adrian Rodriguez) writes:

>Buy "Compilers: Principles, Techniques, and Tools" by Aho, Sethi, and Ullman.

(this in response to the original poster's request for info on yacc/lex/bnf)

Another good source is nearly anything by A. Holub. 
Holub's articles (in C Gazette) and his magnum opus on compiler construction
("writing compilers with c" i think - I don't have it handy)
are chock full of practical explanations and full-length examples.

I find that Holub's book complements the Dragon Book nicely and 
is superior when what you require is a quick example.
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ISC Consultants NYC 212-477-8800 Training/Consulting Since 1973 isc@panix.com
Newsgroups: comp.lang.c
From: dnl@convex.is.macsch.com (David Lombard)
Subject: Re: Question to test general C knowledge
Organization: MacNeal-Schwendler Corp.
Date: Wed, 23 Dec 92 23:05:12 GMT

In article <BzGoGn.A93@cck.coventry.ac.uk> champion@cch.coventry.ac.uk (Alun) writes:
>~   printf("%c", unix["abc"]);
>
>Why does this print 'b' ??


cpp (on a Unix system) replaces `unix' with 1, thus the compiler sees

	1["abc"]

Is that better?

Regards,
DNL

                 MY_COMMENTS = MY_OPINIONS = NOBODY_ELSES;

David N. Lombard    The first thing we do,         The MacNeal-Schwendler Corp
dnl@macsch.com      Let's kill all the lawyers.    815 Colorado Blvd
(213) 259-4911      II Henry VI, IV.ii             Los Angeles, CA  90041
From: s1110238@giaeb.cc.monash.edu.au (Lee Hollingworth)
Newsgroups: comp.lang.c
Subject: Re: Inline ASM in Quick C/ MS C 5.1
Date: 21 Dec 92 07:15:03 GMT
Organization: Monash University, Melb., Australia.

ericwebb@blackwlf.gwinnett.com (eric webb) writes:

>Hi...  Does anyone know if one can do inline ASM in Quick C?  How does
>one do it?  I have version 1.01, but tell me about it even if it's for a
>different version..   Can you do it with MS C 5.1?  I also have a copy of
>it, and if neccessary to do inline ASM, can use it.
>
>Tks!!!

>Eric Webb

Wrong newsgroup Eric...

Not sure what version it was introduced (I know it works with QC2.0+ and
MSC6.0+)..

/*
 * clear a 25 rows * 80 col display
 */
void clearscr(void) {
{
    _asm {
        mov     ah, 06h
        xor     al, al
        mov     bh, 07h
        xor     cx, cx
        mov     dh, 79
        mov     dl, 24
        int     10h
    }
}

Lee Hollingworth
s1110238@giaeb.cc.monash.edu.au
Newsgroups: comp.lang.c
From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
Subject: Re: Function definition style
Organization: Texas Instruments Inc
Date: Thu, 31 Dec 1992 14:10:35 GMT

In <1992Dec30.223045.29467@news2.cis.umn.edu> wright@staff.tc.umn.edu (Mark Wright) writes:

>Is there any good reason not to use the following style for defining
>functions:

>type function_name( varname1, varname2, varname3 )

>type varname1;
>type varname2;
>type varname3;

>I try to use the style in ansi k&r, but I notice that others are using this
>style and I assume they aren't all using pre-ansi compilers.  My problem is
>that to use Brief's function listing command the end paren must be on the same
>line as the function name, which is difficult to do using k&r 2 style if the 
>function needs several structs as parameters.  Besides, it's easier to
>document function parameters with k&r 1 style.  Is there any good reason
>for me to continue to use k&r 2 style (other than the fact that it makes 
>the function declaration in a .h file a simple cut and paste operation)?

I just like the way the old declarations LOOK -- it's nice and
consistent with every other variable declaration in the way that it
declares the parameters.  However, because ANSI has decreed (for what
seem good and sufficient reasons, but I still don't like it) that the
'classic' declarations will not type-check the parameters even if
there is a prototype somewhere which is visible, I try to force myself
to use the new-style declarations when the compiler will support them.

-- 
"Insisting on perfect safety is for people who don't have the balls to live
 in the real world."   -- Mary Shafer, NASA Ames Dryden
------------------------------------------------------------------------------
Fred.McCall@dseg.ti.com - I don't speak for others and they don't speak for me.
From: awright@gssec.bt.co.uk (Alan Wright)
Newsgroups: comp.lang.c
Subject: Re: Need HELP with strptime....any answers/clues?????
Date: 30 Dec 92 16:30:58 GMT
Organization: BT, Software Engineering Centre, Glasgow, UK

Thank you to everyone who replied to my posting regarding the
broken-ness of strptime. I had something like:

   buf = "19921230033515"
   strptime(buf, "%Y%m%d%H%M%S", tm);

The problem is that strptime parses this string (buf) as one number
which is too large, rather than lots of two- and four-digit numbers.
What I needed were a few delimiters - like spaces. My excuse is that
this never occured to me because I was also using strftime and in
this case it is perfectly okay not to use spaces, i.e.

   strftime(buf, DATE_SZ, "%Y%m%d%H%M%S", tm);

I was simply looking for a converse operation. The manual page does
not specify how the format string should be parsed. My fault for not
thinking clearly. Okay so it's not a good excuse.

The following works:

   buf = "1992 12 30 03 35 15";
   strptime(buf, "%Y %m %d %H %M %S", tm);

Thanks,

-- Alan
--------------------------------------------
awright@gssec.bt.co.uk (Alan Wright)
BT, Software Engineering Centre, Glasgow, UK
--------------------------------------------
Newsgroups: comp.lang.c
From: tye@spillman.uucp (E. Tye McQueen)
Subject: Re: Another C palindrome puzzle
Date: Tue, 29 Dec 1992 09:26:27 GMT
Organization: Spillman Data Systems

fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
)mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
)>Or older versions of gcc, which would give up on compiling and
)>run rogue when they happened across a #pragma of any sort?
)
)I think that these versions of gcc are not standard-conforming.
)I don't have the ANSI C standard, but the C++ ARM says that
)"an unrecognized pragma will be ignored", and I think that the
)C standard says something similar.

But, of course, that gcc compiler recognized all pragmas.

)But you're right of course, it's not strictly ANSI conforming.

You seem to be saying that any use of "#pragma" results in a
not-strictly-ANSI-conforming program, which makes it seem silly
to include it as part of the standard.  And illustrating that
point was, as I recall, the main reason that gcc chose to run
rogue.  Though I at least partially agree, I doubt that is, in
fact, what you are were saying; so I apologize for misunder-
standing you.

 tye@spillman.com                         Tye McQueen, E.
----------------------------------------------------------
 Nothing is obvious unless you are overlooking something. 
----------------------------------------------------------
From: scjones@thor.sdrc.com (Larry Jones)
Newsgroups: comp.lang.c
Subject: Re: Questions about token merging and trigraphs
Date: 1 Jan 93 20:46:29 GMT

In article <16297@goanna.cs.rmit.oz.au>, ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
> It is so easy to check for unintended digraphs and so easy to fix them
> that I don't actually worry about this.  I do find it amusing, though,
> that the easy fix (changing ?? to ?\?) involves one of the very characters
> that has a trigraph (??/ => \).  Suppose we decide to use the trigraph for
> backslash, and instead of writing ?\? write ???/?.  Unfortunately, that
> won't be parsed correctly, because ??? is not one of the recognised
> trigraphs, it will be left untouched.  You _must_ use ?\? or string
> pasting to break up the question marks.  And if you _can_ use ?\?, you
> didn't need trigraphs.

Not so.  ANSI 2.2.1.1 Trigraph Sequences says (in part):

	No other trigraph sequences exist.  Each ? that does not
	begin one of the trigraphs listed above is not changed.

Note that it says each ? that does not begin a valid trigraph is left
alone, not each sequence.  Thus, ???/? is parsed correctly: ??? is not
a valid trigraph, so the first ? is left unchanged, ??/ is a valid
trigraph and so is replaced by \, and the final ? is also left alone
resulting in ?\?.
----
Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
larry.jones@sdrc.com  or  ...uunet!sdrc!larry.jones
I hope Mom and Dad didn't rent out my room. -- Calvin
From: matujos@elof.iit.edu (Joe Matusiewicz)
Newsgroups: comp.lang.c
Subject: Problem with string processing.
Date: 2 Jan 93 23:34:46 GMT
Organization: Illinois Institute of Technology, Chicago


   I am having a little problem with string processing.  I have been
programming in C for 6 months, and I just can't figure out the following
problem:

   I need a function to append a character to the end of a string.
I can't find an ANSI function to do so, so I tried to write my own.
Here's what I have:


         void add_char_to_str(char ch, char *str)
         {
1.           char *tmp;
2.           tmp = (char *) calloc (2*sizeof(char));
3.           *tmp = ch;
4.           *(tmp+1) = '\0';
5.           strcat(str, tmp);
             free (tmp);
         }

   What I tried to do here is to create a temporary string, tmp, which
is 2 bytes long.  The first byte is for the character, and the second is
for the null character (to end the string).  Then the temporary string
is to be used with strcat to append it to the end of the target string.

   The problem seems to be in lines 3 and 4.  The character, ch,
doesn't appear as the first character in tmp after I stepped through
it.  I get "\\\ap" in my tmp string after the 4th line is executed.

Can anyone point out what is wrong?


            Please E-mail me at:   matujos@elof.iit.edu

                                   Joe.
Newsgroups: comp.lang.c