HDTenEightyP/NetNews huggingface dataset:
From: woyansky@flamingo.ece.cmu.edu (George J. Woyansky)
Subject: Re: WHAT WENT WRONG?
Originator: woyansky@flamingo.ece.cmu.edu
Reply-To: woyansky@flamingo.ece.cmu.edu (George J. Woyansky)
Organization: Electrical and Computer Engineering, Carnegie Mellon
Date: Thu, 17 Dec 1992 14:55:49 GMT


|> 
|> The following code is intended to compute the factorial of a given
|> number. Unfortunately it gives weird results for numbers larger than 12
|> or so... Does anyone have an idea why? I tried compiling it under Huge
|> memory model and still the same effects.
|> 
|> 
|> 1) #include <stdio.h>
|> 2) 
|> 3) main()
|> 4) {
|> 5)   double x, y;
|> 6)
|> 7)   printf("\nEnter number to factorialize:");
|> 8)   scanf("%d", &x);
|> 9)
|> 10)    for(y=x-1;y>1;y--) x*=y;
|> 11)
|> 12)    printf("\nFactorial= %d\n", x);
|> 13) }
|> 
|> 
|> Undoubtedly the problem comes from playing with numbers that are too
|> big. Is there something obvious that I am overlooking here? Or is there
|> some hidden secret for dealing with big numbers that only rocket
|> scientists and C gurus are aware of? Any help is appreciated!
|> 
|>    David
|>                                                    
|> ----
|> +---------------------------------------------------------------------+
|> | The Cutting Edge BBS (cutting.hou.tx.us)    A PCBoard 14.5a system  |
|> | Houston, Texas, USA    +1 713 466 1525          running uuPCB       |
|> +---------------------------------------------------------------------+
|> 

This program looks as though it was written for int x,y originally and you
wanted to handle bigger numbers and (naively) changed the type of x and y
with no regard for the rest of the program.  You're violating a number
of rules here no matter which way you look at it:

1) You're printf()ing a double using int specifier %d (line 12) 2) You're
scanf()ing a double using int specifier %d (line 3) 3) Not really an error,
but many people will cringe at your use of a double as a loop variable.  

I'm sure that the gurus will find many more things wrong with this 13-line
(including blank lines - please no more comments about programmer
productivity and whitespace counting or return values of function main :) )
program, but here's a relatively simple fix:

#include <stdio.h>

main()
{
    double x;
    int y;                    /* Use an int here for loop counting */

    printf("\nEnter number to factorialize:");
    scanf("%d", &y);
    x = y--;           
    for(;y>1;y--) 
	x*= y; 

    printf("\nFactorial= %lg\n", x); /* Change format specifier for double */
}

-George Woyansky
 ECE Dept., Carnegie Mellon University
 Pittsburgh, PA
Xref: sparky comp.lang.c:18291 comp.std.c:3196
From: martin@mwtech.UUCP (Martin Weitzel)
Newsgroups: comp.lang.c,comp.std.c
Subject: Re:  Is this ANSI: final (long)
Date: 13 Dec 92 12:01:33 GMT
Reply-To: martin@mwtech.UUCP (Martin Weitzel)
Organization: MIKROS Systemware, Darmstadt/W-Germany

In article <Bz3n1I.73o@unx.sas.com> sasghm@theseus.unx.sas.com (Gary Merrill) writes:
:
:In article <alien.01ss@acheron.amigans.gen.nz>, alien@acheron.amigans.gen.nz (Ross Smith) writes:
:
:|> 
:|> I've seen this idiom before, but I've never seen the point of it. Why not just
:|> use a pointer instead of kludging it up with a fake array?
:|> 
:|>    struct FM
:|>       {
:|>       int data_count;
:|>       char *data;     /* Again, might be int for alignment */
:|>       }
:|>       thing;
:|> 
:|>    ...
:|> 
:|>    thing.data = malloc(extra_data_size);
:|>    thing.data_count = extra_data_size;
:
:The point is this:  If you are dynamically allocating *both* the
:structure and the data, the approach you suggest requires *two*
:separate allocations (and two separate frees if you will be freeing
:the stuff).  The goal is to reduce the calls to the memory management
:functions.  Doing so can result in easily measureable performance
:improvements.  Likewise, you have the extra overhead of setting
:the pointer to the new memory, but this isn't much.  So to reduce
:the call overhead you *could* allocate a big chunk and use the first
:part of it for the structure and the rest for the data.

Yes, and there's another point:  With a single allocation you may
memcpy/memmove/memcmp/[f]read/[f]write the whole easily.  Each of
this would become a specialized operation if you separate the size
from the data.
-- 
Martin Weitzel, email: martin@mwtech.UUCP, voice: 49-(0)6151-6 56 83
Newsgroups: comp.lang.c
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: Date -> Day of week conversion
Date: 17 Dec 92 22:09:41 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <1992Dec15.021818.18355@sm.sony.co.jp>, sakamoto@sm.sony.co.jp (Tomohiko Sakamoto) writes:
> In article <Bz3I8K.LDJ@ccu.umanitoba.ca>, ummalik@ccu.umanitoba.ca (Ijaz Rashid Malik) says:
>> Could someone please forward me algorithm to convert the date
>> ([...]) to corresponding day of the week.

> Please try this:
[...]
> 	return (y + y/4 - y/100 + y/400 + "-bed=pen+mad."[m] + d) % 7;

You would be much better off writing "\3\0\3\2\5\0\3\5\1\4\6\2\4"
instead of "-bed=pen+mad."; that way you aren't dependent on ASCII.  (I
assume ASCII is what it's intended to be used with; I didn't go testing
it.)  For example, converting that string to EBCDIC, I find that it's
equivalent to "\5\4\0\6\0\4\0\2\1\1\3\6\5" then....

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: 17 Dec 92 21:55:15 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <1992Dec14.164400.59891@ns1.cc.lehigh.edu>, dsbb@ns1.cc.lehigh.edu (D. SPENCER BEECHER) writes:

> What is the difference between:
> 	varname%3
> and
> 	varname&0x02
> and why might one be more advantageous to use?

One computes remainders modulo three, the other picks out a specific
bit.  You should use the first when you want remainders modulo three,
the second when you want the next-to-lowest bit.  (This strikes me as
sort of like asking for the difference between "x+5" and "x*2".)

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
From: scjones@thor.sdrc.com (Larry Jones)
Newsgroups: comp.lang.c
Subject: Re: WHAT WENT WRONG?
Date: 17 Dec 92 16:13:14 GMT

In article <1992Dec17.113200.4561@email.tuwien.ac.at>, alex@mips.complang.tuwien.ac.at (Alexander Forst) writes:
>      printf("\nEnter number to factorialize:");
>      scanf("%lf", &x);
>              ^^------------------------ you want to input a double value

Good advice so far...

>      printf("\nFactorial= %lf\n", x);
>                            ^^---------- and printf a double value

Nope.  This is one place where scanf and printf are not symmetric.
Since floats are automagically widened to doubles when passed as
arguments to printf, %f is defined as printing a double and %lf is
not defined at all.  Using it causes undefined behavior.
----
Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
larry.jones@sdrc.com  or  ...uunet!sdrc!larry.jones
It's not denial.  I'm just very selective about the reality
I accept. -- Calvin
From: wieck@jwminhh.hanse.de (Jan Wieck)
Subject: Re: Help!!!!!!!!!!!!
Organization: Private Site under Mach386
X-Newsreader: Tin 1.1 PL4
Date: Mon, 14 Dec 1992 22:09:29 GMT

jcontro@engws10.ic.sunysb.edu () writes:
: Hello--

  Hi Jacqueline,

: 
: In a function, I declare a pointer to a structure, say:
:    SOME_STUCT  *Ptr;
: 
: I pass it to a function, like this :
: 
: fn( ..., Ptr );
: 
: recieve it like :  fn( SOME_STRUCT *Ptr ) { ...
: 
: The problem is that inside the funciton I create a linked list,
: of which Ptr is the head. I know it does this correctly.
: But, when the function returns, the space is lost, I think.  Is it
: because I allocated it locally??
: And if so, how is it that you return a linked list from a function>?????

No, it isn't lost. But maybe you never saved the first entry of your
linked list.

I do that kind of job as follows:

...

static struct SOME_STRUCT *ptr = NULL;

...

void append_to_list( /* some passed arguments */ )
{
    static struct **last = &ptr;

    if((*last = (SOME_STRUCT *)malloc(sizeof(SOME_STRUCT))) == NULL) {
	panic("out of memory in append_to_list()\n");
    }

    (*last)->next = NULL;

    /* now you can fill the structure, using (*last)->field */

    last = &((*last)->next);
}


Now, the global variable ptr points to a well terminated, linked list
at any time (even, if the function append_to_list is never called -
at which it points to NULL).

If you declare ptr inside of a function (and not static) be sure,
to free the linked list before leaving the function declaring it. If
you ever need to refill the list (freeing it and filling it again),
make the last-variable global and reset it after freeing.


Until later, Jan

-- 
# Any language keeps its own misunderstandings; #
# why shouldn't programming languages do?       #
#                                               #
#            wieck@jwminhh.hanse.de (Jan Wieck) #
Newsgroups: comp.lang.c,comp.unix.bsd
From: jpm@Logix.DE (Jan-Piet Mens)
Subject: Re: Segmentation faults
Organization: Logix GmbH, Wiesbaden, Germany
Date: Fri, 18 Dec 1992 13:42:25 GMT

In <1gricmINNsl@ub.d.umn.edu> cbusch@ub.d.umn.edu (Chris) writes:
>    Why is the following code producing a segmentation fault???
>I am compiling this code on an Encore Multimax running UMAX 4.3 Unix.

Doesn't matter where you compile it is bad anyway...

void writexy(x,y,s)
int x, y;
char *s;				/* OTHERWISE DEFAULTS TO int !!! */
{
   printf("\33[%d;%dH%s",y,x,s);
}

[ BTW, how about termcap/terminfo ? ]
-- 
    __  _____   __  __ 
   |  ||  _  \ |  \/  |    Logix GmbH                             jpm@Logix.DE
 __|  ||  ___/ |      |    Moritzstrasse 50, +49-611-309797   jpm@logixwi.UUCP
|_____||__|    |__||__|    D-6200 Wiesbaden  ...!uunet!mcsun!unido!logixwi!jpm
Newsgroups: comp.lang.c
From: gcouger@olesun.okstate.edu (Gordon Couger)
Subject: Re: ISAM routines
Organization: Oklahoma State University, Stillwater
Date: Thu, 17 Dec 1992 00:11:57 GMT

In article <1992Dec16.014757.23317@usage.csd.unsw.OZ.AU> M.Jackson@unsw.edu.au writes:
>Does anyone know of any routines to implement ISAM under C ? We are 
>working on a project which needs indexed sequential access and (as 
>always) don't want to reinvent the proverbial wheel.
Mix puts out a set that cost $29.00 US works with MIX, Borland, Turbo, 
 and micorsoft C. 
Their Address:  MIX Software
                1132 commerce Dr.
                Richardson, TX 75081
                Voice 214/783-6001 fax 214 783-1404
 The phone is answered from 9:00 am to 10:00 or 11:00 pm Central standard time.
If you have problems with the girl that answeres the phone ask for Dennis or Jimand they can handle the problem they own the company and will be the one that
answere the pone at night.

I have used their stuff for over ten years and I have always been satisified.
Good luck
Gordon
Gordon Couger
AB5Dg   Agriculture Engineering Oklahoma State University
gcouger@olesun.agen.okstate.edu 405-744-6514 day 744-2794 evenings
From: alane@wozzle.linet.org (J. Alan Eldridge)
Newsgroups: comp.lang.c
Subject: Re: Variable Length Argument Lists?
Date: 13 Dec 92 17:07:56 GMT
Organization: Disorganization

sr@zen.mp.umist.ac.uk (Simon Read) writes:

> What I want to be able to do is to prune off a few of the arguments in
> an ... list and pass the rest on to another function. Something like
> the following C-style code would suggest:
> 
> void recursive1 (int a, ...)
> {
>     printf("%d, ", a);
>     if (a == 0)
> 	recursive1(...);
>     else
> 	recursive1(a, ...);
> }

You can't get there from here. Best you could do, and this isn't really
very safe at all, is:

void rhelper(va_list ap)
{
    va_list asave = ap;

    int a = va_arg(ap,int);

    if (a == 0)
        rhelper(ap);
    else
        rhelper(asave);
}

void recursive1(int a, ...)
{
    rhelper((va_list)&a);
}

Please, folks, no flames. I merely suggest how he can accomplish his
objective, I do _not_ recommend the practice, nor do I claim it will 
even work on all architectures.

    
alane@wozzle.linet.org (J. Alan Eldridge)
Fido: The University of Walamaloo 1:272/38.473
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: Question to test general C knowledge
Date: 11 Dec 92 19:33:46 GMT
Organization: McGill Research Centre for Intelligent Machines

In article <behrenss.724026637@hphalle6>, behrenss@Informatik.TU-Muenchen.DE (Soenke Behrens) writes:

> Hmm. ++i would mean it is incremented before using it in the
> expression.  Means I get three.

Er, no.  ++i means the value is the value after the increment.  The
increment itself may happen any time between the previous and next
sequence points; in particular, it may happen after the assignment, and
it may take the form of an increment or a storing of the new value.

That is, it could be

	i = (old value plus 1)      -- assignment
	i = (old value plus 1)      -- increment
or
	i = (old value plus 1)      -- assignment
	i = (current value plus 1)  -- increment
or
	i = (old value plus 1)      -- increment
	i = (old value plus 1)      -- assignment

Or, of course, since the same lvalue is being modified more than once,
this is all academic anyway; it's equally legal to compile

	i = 42                      -- undefined behavior

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
Newsgroups: comp.lang.c
From: steve@taumet.com (Steve Clamage)
Subject: Re: Questions about token merging and trigraphs
Organization: TauMetric Corporation
Date: Fri, 18 Dec 1992 16:20:11 GMT

scjones@thor.sdrc.com (Larry Jones) writes:

>> BECAUSE OF THEM, it is **IMPOSSIBLE** to write code that is both
>> K&R I and ANSI!!!

>Nonsense -- simply avoid using those combinations of characters.  Since
>you presumably have to continue to support your existing file format,
>you can't follow that advice, but you can do something like:

>	const char delims[5][4] = {
>		{ '?', '?', '!', '\0' }, ...

Actually, it's easier than that.

You can replace, for example, "??!" with "?\?!".
The escaped second question mark breaks up the trigraph.

This means you can write a simple filter (or editor script) which
blindly replaces the trigraph sequences with versions as above.
You can apply it to any code which was not intended to be compiled
as having trigraphs.  The result will work with both K&R and Standard
compilers.  (If you used a trigraph-like sequence in a comment, you
would also get the escaped question mark there.)
-- 

Steve Clamage, TauMetric Corp, steve@taumet.com
Newsgroups: comp.lang.c
From: jar@solva.ifi.uio.no (Jo Are Rosland)
Subject: Re: Question to test general C knowledge
X-Md4-Signature: 26f0d8e13c00a2845a2e57509e2389f6
Organization: Dept. of Informatics, University of Oslo, Norway
	<1992Dec11.180939.20726@crd.ge.com>
	<1992Dec12.230520.771@thunder.mcrcim.mcgill.edu>
	<1992Dec13.051442.1867@crd.ge.com>
Date: Sun, 13 Dec 1992 22:54:54 GMT
Originator: jar@solva.ifi.uio.no

In article <1992Dec13.051442.1867@crd.ge.com> volpe@bart.NoSubdomain.NoDomain (Christopher R Volpe) writes:
   |> 
   |> Based on a sequence like
   |> 
   |>         ! compute needed values
   |>         addl3   _i,$1,r0        ! compute value of ++i
   |>         ! sequence point; do accumulated side-effects
   |>         movl    r0,_i           ! store value of ++i into i
   |>         incl    _i              ! increment i
   |> 
   |> Thus we see the wisdom of ANSI's rule :-)

   Umm. I question whether it would be legal for the compiler to emit
   such code. The reason is that the value of the "++i" expression is
   "the value of i after the assignment". The first assembly statement
   computes this value as "3". However, the "value of i after the assignment"
   is determined by the result of the "incl _i" statement, and that 
   value is 4, which contradicts the definition of the value of the "++i"
   expression. 

An expression in C has a return value.  Some expressions also have
side effects.  The _return_value_ of "++i" is 3 (given 2 as the
original value), while the _side_effect_ is to increment "i".  Trouble
is, the compiler doesn't have to compute the return value and execute
the side effect at the same time.

The following is the likely way the compiler will operate:

- The return value of "++i" as well as the address of "i" will have to
  be computed before the "=" is performed.

- The side effect of incrementing "i" can be performed before, during
  or after these computations.

- The compiler can perform the incrementing of "i" by assigning it the
  return value of "++i" at some point after it's computed, or by simply
  incrementing it.

But, due to the "undefinedness" of the construct, none of these are
guarantees.  The compiler could opt to do something entirely
unexpected, like bringing about world peace.

Hope this helps,

--
Jo Are Rosland
jar@ifi.uio.no
Newsgroups: comp.lang.c
From: pdh@netcom.com (Phil Howard )
Subject: Re: Test for general 'C' knowledge
Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
Date: Tue, 15 Dec 1992 04:08:58 GMT

pegasus@csd4.csd.uwm.edu writes:

>AM I less of a programmer if I have to look up QuickSort in a reference book?
>I was taught in school that it is not neccessary to memorize any type of
>sort.

I agree with the way you were taught.  The good algorithms are not that
easy to memorize anyway; even good programmers could only memorize a few
of them.  No reason to expect QuickSort to be among them.  Also, it would
be irrelevant for a test of your knowledge of a particular language.


>About the question:   i = i++
>WHo the heck would write that anyway?

Agreed.  It may or may not be definable (I don't care because I would not
do it even if it was definable).  It depends on the working of the question.


>I am just wondering because I would hate to apply for a job and be told
>that I am incomptent because of questions like these.

I would not work somewhere that asked questions like that.
-- 
/************************************************************************\
| Phil Howard,  pdh@netcom.com,  KA9WGN    Spell protection?  "1(911)A1" |
| "It's not broken... it's just functionally challenged" --Phil and Pete |
\************************************************************************/
From: pjh@mccc.edu (P. J. Holsberg)
Newsgroups: comp.lang.c
Subject: argv[] as a general purpose 2D array
Date: 20 Dec 92 19:24:57 GMT
Organization: The College on the Other Side of U. S. 1

Exam question asked that if the name of the file was not typed on the
command line, the user should be prompted for it.  Most set up a char
array to hold the name of the file, and strcpy'd to it from argv[1] if
the name was in argv[1].

One student decided to save some memory space and scanf'd the prompted
name directly to argv[1]!

Are there any problems to that approach??

Thanks,
Pete
From: gowen@jade.tufts.edu (G. Lee Owen)
Newsgroups: comp.lang.c
Subject: Re: What do you say.
Date: 15 Dec 92 03:12:09 GMT
Organization: Tufts University - Medford, MA


>Here's a question for you.  What do you say to a co-worker who
>asks you "What is the difference between equals and equals equals?"
>
>(this guy was recently hired for software developement in C)

	you say, "Well, it's a matter of style.  It's good style
to use double equals to emphasize things."
	Then you buy him a going away present.

	8-)
--
--Greg Owen
	gowen@forte.cs.tufts.edu, gowen@jade.tufts.edu
"C Spot. C Spot run. C Spot run without a core dump! Run, Spot, Run!"
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Newsgroups: comp.lang.c
Subject: Re: How to do an efficient ROTATE in C?
Date: 16 Dec 92 09:03:22 GMT
Organization: McGill Research Centre for Intelligent Machines

> Distribution: ba

Someone's leaking ba...

In article <71576@cup.portal.com>, Aurelius@cup.portal.com (Mark Christian Barnes) writes:

> Most C compilers will do rotates, i.e. logical shifts,

As I understand and use the terms, a rotate and a logical shift are not
at all the same thing.  As I use the terms, given a 16-bit datum
holding 0x74a0, a logical shift left by 4 bits would produce 0x4a00,
while a rotate left by 4 bits would produce 0x4a07.

Of course, this is only what I thought the terms meant.  I had assumed
that the original poster wanted a rotate in my sense of the term,
because otherwise, as you point out, it's pretty trivial.

					der Mouse

			    mouse@larry.mcrcim.mcgill.edu
From: mr804331@cs.nthu.edu.tw (L.C. Lin)
Newsgroups: comp.lang.c
Subject: Re: Need Help! Translating Turbo-C to Micrisoft Quick-C
Date: 12 Dec 92 11:22:01 GMT
Organization: National Tsing Hua University (HsinChu)

The  header file 'graphics.h' is uniquely implemented  by Borland 
Cor. it is not standard, so if you want to write graphics program 
under MS C, you must know how MS C implement their graphics    
environment.

 L.C. Lin
From: droelke@spirit.aud.alcatel.com (Daniel R. Oelke)
Newsgroups: comp.lang.c
Subject: What do you say.
Date: 14 Dec 1992 08:15:18 -0600
Organization: UTexas Mail-to-News Gateway
NNTP-Posting-Host: cs.utexas.edu


> >Here's a question for you.  What do you say to a co-worker who
> >asks you "What is the difference between equals and equals equals?"
> >
> >(this guy was recently hired for software developement in C)
>
> What *did* you say?

Well, I nicely explained the difference (after surpressing a BIG snicker)
and then explained my experience to our group leader.  

I beg a thousand pardons from being somewhat ambigious in my first post
as to my knowledge of C.  *YES*, I do know the language quite well, it's just
at the time I was somewhat frustrated with my situation, and apalled that
someone so unqualified got through the same hiring process I did.
From what I can tell it boils down to politics :-(

Now, because our newsfeed here is very behind and spotty, would someone be so
kind as to roll up a .tar.Z file with all of the responses, and either
make it available for me via anonymous FTP, or email it to me.

Other responses I received:

> From: nelson@berlioz.nsc.com (Taed Nelson)
> You could tell them that some equals are more equal than others.

> From: Jutta Degener <jutta@cs.tu-berlin.de>
> "The first tests for future, the second for present equality."
> (Disclaimer: I didn't invent that joke.)


Newsgroups: comp.lang.c