HDTenEightyP/NetNews huggingface dataset:
From: scoile@gmuvax2.gmu.edu (Steve Coile)
Subject: Re: Detecting Integer Overflow/Underflow
Organization: George Mason University, Fairfax, Va.
Date: Sun, 23 Aug 1992 13:36:20 GMT

David desJardins writes:
>
>unsigned int adduint (unsigned int a, unsigned int b, int &overflow) {
>  /* a and b are unsigned integers, WORDSIZE is the length of each.  The
>     return value is the sum of a and b, and the value of overflow is 1
>     if overflow occurred, or zero otherwise. */
>
>  unsigned int sum;
>  unsigned int temp;
>
>  sum = a + b;
>  temp = ((a ^ sum) & (a ^ b)) ^ b;
>  *overflow = temp >> (WORDSIZE - 1);
>  return sum;
>}

Could someone please, PLEASE explain what is going on with

	((a ^ sum) & (a ^ b)) ^ b

What is the justification for doing this (i.e. how in the WORLD would someone
figure this out that THIS is the way to do it?????)

Thanks!

 Steve "Stevers!" Coile                    scoile@gmuvax[{.BITNET|[2].gmu.edu}]
            "Maturity is knowing when and where to act immature"
From: maceache@fox.nstn.ns.ca (Tim Maceachern)
Newsgroups: comp.programming
Subject: Re: Teaching the basics
Date: 21 Aug 92 14:16:17 GMT
Organization: NSTN Network Operations Centre, Nova Scotia, Canada

I think some of the arguments in this thread would have to be modified
if c++ were used for the beginning language with a suitable class 
library for beginners -- for instance the var class recently posted.  In
particular, would it be possible to teach a c++ course without pointers
if everything is hidden in a supplied object?

I think it is becoming necessary to learn OOP directly, from the start.

*******************************************************************
*         Tim MacEachern         * Tim_MacEachern@hawk.nstn.ns.ca *
*     Software Kinetics Ltd.     *  or maceache@hawk.nstn.ns.ca   *
* Dartmouth, Nova Scotia, Canada *                                *
*           Opinions expressed are the author's only              *
*******************************************************************
From: markh@csd4.csd.uwm.edu (Hunk)
Newsgroups: comp.programming
Subject: Re: what skills does a programmer need
Date: 17 Aug 92 15:55:45 GMT
Organization: Computing Services Division, University of Wisconsin - Milwaukee

Learning: the ability to master anything in a short time when required.
Coding:   the ability to write code that is clear and concise.
Newsgroups: comp.programming
From: mhcoffin@tolstoy.uwaterloo.ca (Michael Coffin)
Subject: Re: ANSI C, was Re: Teaching the basics
Organization: Dept. of Computer Science, University of Waterloo
	<ratner.714247759@ficus.cs.ucla.edu> <13226@bnr-rsc.UUCP>
	<MHCOFFIN.92Aug20162507@tolstoy.uwaterloo.ca>
	<NICKEL.92Aug21010722@desaster.cs.tu-berlin.de>
Date: Fri, 21 Aug 1992 13:14:57 GMT

In article <NICKEL.92Aug21010722@desaster.cs.tu-berlin.de> nickel@cs.tu-berlin.de (Juergen Nickelsen) writes:
> 
> In article <MHCOFFIN.92Aug20162507@tolstoy.uwaterloo.ca>
> mhcoffin@tolstoy.uwaterloo.ca (Michael Coffin) writes:
> 
> > It is true that if you use a certain amount of discipline and make
> > sure that the same prototype appears in both places---by putting it in
> > an include file---the compiler will detect the error.  The problem is,
> > there isn't any enforcement of this policy.
> 
> This is indeed a weakness of the standard, but at least gcc can be
> told to issue a warning when a function call without a previous
> prototype is encountered. From the manual:
> 
>     `-Wmissing-prototypes'
> 	 Warn if a global function is defined without a previous prototype
> 	 declaration.  This warning is issued even if the definition itself
> 	 provides a prototype.  The aim is to detect global functions that
> 	 fail to be declared in header files.
> 
> But using this is a major pain on a system without ANSI Header files.

And there is no guarantee that the prototype "seen by" the global
definition is the same prototype that is seen by uses of that
function.  It's up to the programmer to make sure the prototype gets
put in an include file and included in both places.

-mike
From: jhenders@jonh.wimsey.bc.ca (John Henders)
Newsgroups: comp.programming
Organization:  One of these days for sure
Subject: Re: finding 1st one in integer
	<1992Aug06.114817.20716@donau.et.tudelft.nl>
	<BsM2z9.1KA@metropolis.com> <1992Aug9.072022.9391@linus.mitre.org>
Reply-To: jhenders@jonh.wimsey.bc.ca
X-Software: HERMES GUS 1.03 Rev. Apr 14 1992
Date: Tue, 11 Aug 1992 18:50:04 -0700

In <1992Aug9.072022.9391@linus.mitre.org>, Randy Crawford writes:
>
>And BTW, I too would be interested in a variant alg which could identify the
>highest bit set in O(1) or O(2).  I'll bet it's impossible since the hardware 
>doesn't naturally shift the bits to the right.
>
	68k chips support a rotate right or left which would allow a rotate, 
followed by a test of the lsb.  Do any other chips have rotate? 
	Of course, this wouldn't be portable, as it would have to be done in
assembly.


-- 
jhenders@jonh.wimsey.bc.ca
From: dan@minster.york.ac.uk
Newsgroups: comp.programming
Subject: Re: A LITTLE BRAIN... in parallel II
Date: 18 Aug 92 16:57:21 GMT
Organization: Department of Computer Science, University of York, England

OK... for all of you who didn't spot the mistake this it the correct
version:

END = p? -> d! -> SKIP
P   = input?ch ->
	IF ch == <CR>
	    (f:M_META//(f.nw? -> p! -> d? -> output!ch -> nw! -> SKIP))
     ELSIF ch == <SPACE>
            p! -> d? -> output!ch -> nw! -> SKIP
      ELSE
	    (n:P //(n.p? -> p! -> d? -> output!ch -> n.d! -> SKIP))
M_META = END || P

META = ((nw? -> SKIP) || M_META) -> META

I know that the mistake was obvious and I am quite embarased! (for those
who didn't see it : the previous wersion worked for 2 words only (and
for 42 sentences, for infinitie value of 42; as long as the sentences
were 2 words long. Any longer sentences were truncated: BAZ BAR FOO
became FOO BAR.)

Some of you might complain that I didn't bother with proper formating.
That is left as an easy exercise for the reader.

                       Daniel Kustrin
              Distributed Ada Debugging Group
                     University of York
                       York,  England
                   dan@minster.york.ac.uk
From: dan@minster.york.ac.uk
Newsgroups: comp.programming
Subject: Re: A LITTLE BRAIN... in parallel
Date: 18 Aug 92 16:22:29 GMT
Organization: Department of Computer Science, University of York, England


Dear Netters,

Here is my solution to the little problem someone posted a while ago.
I am not too happy to see that more and more people are getting stuck
into the arcane ways of C. comp.lang.c is a good place for that and I
though that something a little different might be of interest.
(... I am being a hypocrite; I spend my days hacking C as well)

The following proglet (if I am allowed to call it so) reads lines and
prints them in the reverse, while the words stay properly orientated;
so FOO BAR BAZ becomes BAZ BAR FOO. As it stands the program works for a
single line of text. It is written in Hoare's CSP language and my
colleagues and I believe that it works. The version that worked for a
single word only was tested in Ada and it worked properly. 

The following code DOESN'T use a stack or a list or env or anything like
that. It uses a PROCESS per character. Each char is read by a single
process and printed by that same process. BAZ BAR FOO would need 12
separate processes.

If CSP was executable, running META would do the trick.

END = p? -> d! -> SKIP
P   = input?ch ->
	IF ch == <CR>
            (f:META//(f.nw? -> p! -> d? -> output!ch -> SKIP))
     ELSIF ch == <SPACE>
            p! -> d? -> output!ch -> nw! -> SKIP
      ELSE
            (n:P //(n.p? -> p! -> d? -> output!ch -> n.d! -> SKIP))
META = END || P

where <CR> is ASCII 0x0d and <SPACE> is ASCII 0x20
(note [pd][!?] implies that a communication channel is engaged, but
that we are NOT interested in the actual messages that will be passed.
The channels are only used for synchronization.)

Beware of the above code...
I didn't even proved it correct, but I suppose I could if needed.

p.s. as I said I am NOT sure that it works, but I give it a very high
probability of correctness. :)

p.p.s Just an afterthought if you want it to work for more then one line
define another process, say TEXT as follows:

	TEXT = META -> TEXT

p.p.p.s I will try to convince my colleague to translate all of the
above into Ada. If he does, I'll post it.



                       Daniel Kustrin
              Distributed Ada Debugging Group
                     University of York
                       York,  England
                   dan@minster.york.ac.uk
From: ross@cc.gatech.edu (Rosario DSouza, J)
Newsgroups: comp.programming
Subject: Re: Teaching the basics
Date: 18 Aug 92 19:05:06 GMT
Organization: College of Computing, Georgia Tech

In article <1992Aug17.123916.14815@husc13.harvard.edu>
peregrin@husc13.harvard.edu writes:

> [...] Basically, I'm giving you all the oportunity to tell a programming
> teacher what to better prepare students with.

I believe that one important skill that a programmer should be
equipped with is the desire to be a perfectionist - in the things
that matter. Careless thinking habits when writing a program can lead
to the waste of a lot of time in debugging the program.

..Ross D'Souza
ross@cc.gatech.edu
Newsgroups: comp.programming
From: nickel@cs.tu-berlin.de (Juergen Nickelsen)
Subject: Re: ANSI C, was Re: Teaching the basics
Reply-To: nickel@cs.tu-berlin.de
Organization: STONE Project, Technical University of Berlin, Germany
Date: Sat, 22 Aug 1992 15:06:07 GMT

In article <1992Aug21.154839.2664@organpipe.uug.arizona.edu>
dave@cs.arizona.edu (Dave Schaumann) writes:

> In article <NICKEL.92Aug21010722@desaster.cs.tu-berlin.de> nickel@cs.tu-berlin.de (Juergen Nickelsen) writes:
[...]
> ]> But using this is a major pain on a system without ANSI Header files.
> 
> IMHO, you should do it anyway.  Make your own header files with the
> appropriate prototypes if you need to.  I don't know how many times the
> prototype for fprintf() has saved me from a core dump when I forgot to
> include the initial FILE * parameter...

This would mean to rewrite 3 MB of system header files (this is SunOS
only, but I also work with other platforms), ~1.5 MB of X11 header
files, etc., for each new release... does anyone volunteer? :-}


--
Juergen Nickelsen
From: dbsjwb@Edm.Arco.COM
Newsgroups: comp.programming
Subject: New application methodology
Date: 13 Aug 92 18:57:16 GMT
Reply-To: bielak@arco.com
Organization: ARCO Exploration and Production Technology
Originator: dbsjwb@doofus


This is not algorithm stuff, but I thought it pertains enough to 
comp.programming to post here. 

After witnessing a number of documents describing in (sometimes gory)
detail the _shoulds_ of the definition/analysis/design/programming/testing/
acceptance flow-chart ideal, it strikes me that I have never actually
witnessed the details of such an ideal happen in "real life".

As a consequence, what happens (at least in my corner of the world) is
that many times _nothing_ approaching the suggested documents, reviews,
etc. actually are produced. I believe that there must be some methodology
which permits a one-person project a chance of fulfilling all the stated
method requirements, as well as encouraging a multi-person project to
fully and adequately state and describe the stages of the project life 
cycle. Thus I turn to your experience for suggestions.

What kind of documents do you require (or are required of you) ?
Who produces them?
Do you use document templates? What do they look like?
How detailed are the detailed design specs? How long do they take to
produce? Who writes them (mgr, pgmr, user-support, security guard) ?
Do you have code walk-throughs/reviews? Who participates? What do
you actually do? How long does it take?
Etc.

What I am searching for is a generalized schema which would encourage
use for small one-person and huge multi-person projects. Not what
SHOULD be done, but what actually IS done.

OTOH, has this been discussed before, and where should I look for 
the answers?

Email or post... an inquiring mind wants to know.

thanks in advance,
jwb



-- 
bielak@Arco.COM             ARCO Exploration and Production Technology
james.bielak@Edm.Arco.COM   2300 W. Plano Parkway PRC-D1139A
(214) 754-6184              Plano, TX 75075
From: anderson@Software.Mitel.COM (David Anderson)
Newsgroups: comp.programming
Subject: Re: Teaching the basics
Date: 18 Aug 92 19:51:42 GMT
Organization: Mitel. Kanata (Ontario). Canada.

In article <Bt6DGq.HuB@metropolis.com> robert@metropolis.com (Robert Munyer) writes:
>Yo, James!
>
[ Excellent Testing remarks delete...]

>P.S.  I know that C is fashionable, but it's really not a very good language
>for teaching complete beginners.  C has a lot of "traps and pitfalls" for the
>unwary.  When you're not even ready to learn about pointers, C is not much
>more than a twisted version of Pascal.  What good is C without pointers?
>
>They'd be better off starting with Pascal (or Modula-2 or -3), and switching
>to C only after they've learned how to use pointers in Pascal.  Of course,
>often there are political considerations, and there's not much you can do.

I currently teach C and have taught Pascal for the local college here and
I tend to agree with Robert on the above comments.

  o C is *not* a beginners  language.

    I have had students who had no prior programming knowledge attend my C
    class. I told them that they may find it to be an "overwelming" course.
    These students have either *barely* passed or have dropped out all
    together. This won't apply to all students, but in my experience C and
    the beginner programmer do not go well together!

  o Robert's other comment on Pointers is very valid. I cannot see how you can
    teach a C course without teaching Pointers. In Pascal, I could "get away"
    with not teaching pointers until the very end of the course because of
    Pascal's call by reference and value mechanisms. In C however, the concept
    of pointers *must* be taught at the very start of the course.

Other general points in teaching any language:

  o Style! Teach the student consistent coding practices. Readability counts
    higher than fancy cryptic statements.

  o Meaningful Identifiers. Please make sure the student is not using variable
    names like "a" when you really mean something like "tax_rate"!

  o Teach them modular programming techniques. Emphasize how to make proper
    use of prototypes, static, auto, and global variables etc...

That's most of the important ones anyway...

Good luck in your class...

Regards,

/David
-- 
-------------------------------------------------------
David AR Anderson   Email: anderson@Software.Mitel.COM
Software Tools and Integration
Mitel Corporation   Disclaimer: My opinions are my own!
Newsgroups: comp.programming
From: robert@metropolis.com (Robert Munyer)
Subject: Re: finding 1st one in integer
Organization: Metropolis Software, Inc.
Date: Thu, 13 Aug 1992 10:59:29 GMT

In article <H.b_Q8qXezVYo@jonh.wimsey.bc.ca> jhenders@jonh.wimsey.bc.ca writes:

> 	68k chips support a rotate right or left which would allow a rotate,
> followed by a test of the lsb.  Do any other chips have rotate?
> 	Of course, this wouldn't be portable, as it would have to be done in
> assembly.

Yes, many other chips have rotate.  In fact, I can't think of one that doesn't.
And it DOESN'T have to be done in assembly; C has the << and >> operators,
which compile directly into bit-shift instructions (not exactly the same thing
as rotate, but close enough for this particular situation).

But the point of this discussion is that we're looking for ways to find the
most significant "one" bit (i.e., count the number of leading 0's) WITHOUT
having to go through a loop 31 times.

______________________________________________________________________
Robert Munyer            |   "I may be synthetic, but I'm not stupid."
robert@metropolis.com    |      -- Bishop, _Aliens_
From: steve@fulcrum.oz.au (Steve Taylor)
Newsgroups: comp.programming
Subject: Re: what skills does a programmer need
Date: 19 Aug 92 01:47:20 GMT
Organization: The Fulcrum Consulting Group

In <17498@autodesk.COM> dansmith@Autodesk.COM (Daniel Smith) writes:

>In <1992Aug17.155545.15339@uwm.edu> markh@csd4.csd.uwm.edu (Hunk) writes:

>> Learning: the ability to master anything in a short time when required.
>> Coding:   the ability to write code that is clear and concise.

>	also Attitude: knowing that just because you've got a degree, that
>doesn't mean you can rest on your laurels and stop learning.  Keep an open
>mind.

>	Motivation: I've run into too many "programmers" who just got

Organisation: Programming is not really hard per se. - writing a small
program is something almost anyone can do. Writing an extremely large
program is something almost no one can do well.


							Steve
							steve@fulcrum.oz.au
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.programming
Subject: Recursion (was Re: Teaching the basics)
Date: 21 Aug 92 00:41:03 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <1992Aug19.154830.11787@uwm.edu>, markh@csd4 (Hunk) writes:
>In article <14066@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
>>If you don't know recursion, you don't know programming.  It is one of the
>>simpler concepts in computing.  (Much simpler than mutable variables, IMHO.)
>
>I think recursion is a farce.  And just to rub it in, here's the Towers of
>Hanoi
[code deleted]

So you think recursion is a farce.  Care to explain why?  True, there is
no problem that can be solved without it, but there are many problems
where the solution is naturally modeled by recursion:

  -top-down parsing
  -the Akerman function
  -most of the nlogn sort algorithms
  -operations on any recursively defined structure
   o trees (depth-first search is an easy example)
   o lists (check out Lisp)

Also, induction is a powerful algorithm design and analysis tool, which
often naturally leads to recursive solutions.

If you study recursion, (as in Lisp, for example), you will find that in
many ways, recursion is just another way to iterate.  And certainly,
iteration is a valid and useful tool in programming.

-- 
You unlock this door with the key of imagination.  Beyond it is another
dimension: a dimension of 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.
Newsgroups: comp.programming
From: moose@svcdudes.com
Subject: Re: When should a debugger be used?
Reply-To: moose@svcdudes.com
Organization: Software Ventures, Inc.
Distribution: na
Date: Thu, 20 Aug 92 16:37:23 GMT

In article <6453@fury.BOEING.COM> cek@sdc.boeing.com (Conrad Kimball) writes:
> |> >4.  Divide-and-conquer when things go wrong by adding some output  
somewhere
> |> >    (usually an fprintf() added at a strategic spot).
> 
> And what do you do when the problem goes away when you add the fprintf()?
> I've had that happen.  A bad pointer leading to trashed memory, and
> inserting more code moves things around so the trashed memory no longer
> causes the program to fail...

Don't put in bad pointers in the first place :->.  

--
Michael Rutman			|	moose@svcdudes.com
Cubist				|	makes me a NeXT programmer
Software Ventures		|	maker of MicroPhone II
#include <std.disclaimer>

P.S.  It's a joke for the humor impaired.
From: dave@cs.arizona.edu (Dave Schaumann)
Newsgroups: comp.programming
Subject: Re: ANSI C, was Re: Teaching the basics
Date: 21 Aug 92 15:48:39 GMT
Reply-To: dave@cs.arizona.edu (Dave Schaumann)
Organization: University of Arizona

In article <NICKEL.92Aug21010722@desaster.cs.tu-berlin.de> nickel@cs.tu-berlin.de (Juergen Nickelsen) writes:
]> 
]> 
]>     `-Wmissing-prototypes'
]> 	 Warn if a global function is defined without a previous prototype
]> 	 declaration.  This warning is issued even if the definition itself
]> 	 provides a prototype.  The aim is to detect global functions that
]> 	 fail to be declared in header files.
]> 
]> But using this is a major pain on a system without ANSI Header files.

IMHO, you should do it anyway.  Make your own header files with the
appropriate prototypes if you need to.  I don't know how many times the
prototype for fprintf() has saved me from a core dump when I forgot to
include the initial FILE * parameter...

(also check out the thread on comp.lang.c about atof()... a warning of
missing prototype would've solved that problem virtually before it started)

-- 
What signature?
Newsgroups: comp.programming
From: cg@myrias.ab.ca (Chris Gray)
Subject: Re: Teaching the basics
Summary: Recursion is often good
Organization: Myrias Research Corporation
Date: Thu, 20 Aug 92 14:43:04 GMT

In article <1992Aug19.154830.11787@uwm.edu> markh@csd4.csd.uwm.edu (Hunk) writes:
>In article <14066@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
>>If you don't know recursion, you don't know programming.  It is one of the
>>simpler concepts in computing.  (Much simpler than mutable variables, IMHO.)
>
>I think recursion is a farce.  And just to rub it in, here's the Towers of
>Hanoi (up to N = 31, I'm assuming long integers are 32 bits) without it (in C):

[two non-recursive Towers of Hanoi programs deleted]

An excellent example of why recusion is often a good thing! I assume thats
what you had intended to show? Your programs had an unobvious limitation
not in the simple recursive form, contained (ick!) hidden gotos, and gave
no clue from their form as to what they were intended to compute. Determining
their correctness could be tricky. Back when I was teaching undergrad C.S.,
I would have loved your programs, as examples of why recursion can be good,
and also as examples of how not to program. A marvelous collection of non-
standard usage too, like capitalized local variables, multiple statements
on a line, using comma operators where semicolons work just as well, etc.

If I misinterpreted your posting, and you actually believe those are examples
of good programming, well, er, ...

-- 
Chris Gray	Myrias Computer Technologies Inc.   (403) 463-1337
	cg@myrias.ab.ca          ...!uunet!myrias!cg
-- 
Chris Gray	Myrias Computer Technologies Inc.   (403) 463-1337
	cg@myrias.ab.ca          ...!uunet!myrias!cg
Newsgroups: comp.programming