[comp.sys.amiga] Is this a Manx Bug?

joels@tekred.UUCP (01/29/87)

I recently ported a UNIX program to the Amiga. All went well execpt for
one GURU that was caused by an index that was not initialized to zero
at every entry to a subroutine. I put in an 'i=0;' and fixed it.
later I was reading my C manual and it said that all 'auto' variables
should be automaticly initialized to zero at every entry to the subroutine.
The UNIX C does this, but Manx does not. Is this a Manx bug?

Joel Swank
Tektronix, Redmond, Oregon

dillon@CORY.BERKELEY.EDU.UUCP (01/30/87)

>I recently ported a UNIX program to the Amiga. All went well execpt for
>one GURU that was caused by an index that was not initialized to zero
>at every entry to a subroutine. I put in an 'i=0;' and fixed it.
>later I was reading my C manual and it said that all 'auto' variables
>should be automaticly initialized to zero at every entry to the subroutine.
>The UNIX C does this, but Manx does not. Is this a Manx bug?
>
>Joel Swank
>Tektronix, Redmond, Oregon

	Only static and global variables are 0 initially.  Auto (stack)
variables are not initialized at all and thus contain random values.  You
either misinterpreted the C manual or the C manual is wrong.


				-Matt

stroyan@hpfcdc.HP.COM (Mike Stroyan) (01/31/87)

>later I was reading my C manual and it said that all 'auto' variables
>should be automaticly initialized to zero at every entry to the subroutine.
>The UNIX C does this, but Manx does not. Is this a Manx bug?

Your UNIX C compiler is at fault.

Kernighan and Ritchie, "The C Programming Language", page 198 states that
"Automatic and register variables which are not initialized are guaranteed
to start off as garbage."

Your compiler just wasn't using rotten enough garbage. :-)

Mike Stroyan, hpfcla!stroyan

gary@mit-eddie.UUCP (01/31/87)

In article <958@tekred.TEK.COM>, joels@tekred.TEK.COM (Joel Swank) writes:
>
> later I was reading my C manual and it said that all 'auto' variables
> should be automaticly initialized to zero at every entry to the subroutine.
> The UNIX C does this, but Manx does not. Is this a Manx bug?

No, the Manx manual explicitly states that auto variables are guaranteed to be
garbage.  Whatever is left on the stack becomes the value of the variable.

The C language itself definitely does not guarantee that auto variables
are initialized.  I think it guarantees that global variables are set to 0,
though.

	Gary

higgin@cbmvax.UUCP (01/31/87)

In article <958@tekred.TEK.COM> joels@tekred.TEK.COM (Joel Swank) writes:
$
$I recently ported a UNIX program to the Amiga. All went well execpt for
$one GURU that was caused by an index that was not initialized to zero
$at every entry to a subroutine. I put in an 'i=0;' and fixed it.
$later I was reading my C manual and it said that all 'auto' variables
$should be automaticly initialized to zero at every entry to the subroutine.
$The UNIX C does this, but Manx does not. Is this a Manx bug?
$
$Joel Swank
$Tektronix, Redmond, Oregon

I don't know what C manual you have, but I've never read anywhere that
automatic variables are initialized.  They're created on the stack and
if you have any big automatic variables on the stack, that's going to be
a LOT of overhead on each call to the function just to zero the memory
used for auto variables.

But anyway, no, Manx code DEFINITELY does not automatically initialize
variables to 0.  Maybe for int's etc it wouldn't be too hard to do this, but
Joel, if you had auto floats and doubles, it would have to put the appropriate
floating point representations of zero onto the stack rather than just
flush it wish zeroes (ick).

	Hope this helps,
		Paul.

Disclaimer: I still work for myself (until Monday) and my opinions are still
just my own.

papa@bacall.UUCP (02/01/87)

>Joel Swank writes: 
> I recently ported a UNIX program to the Amiga. All went well execpt for
> one GURU that was caused by an index that was not initialized to zero
> at every entry to a subroutine. I put in an 'i=0;' and fixed it.
> later I was reading my C manual and it said that all 'auto' variables
> should be automaticly initialized to zero at every entry to the subroutine.
> The UNIX C does this, but Manx does not. Is this a Manx bug?
>

Sorry to say, but you are wrong and MANX is right.  I quote from the "C" bible
(I mean K&R, p. 198):

"Static and external variables which are not initialized are guaranteed to 
start off at 0; automatic and register variables which are not initialized 
                ^^^^^^^^^
are guaranteeed to start off as garbage".
                                ^^^^^^^

Also note that there isn't such a thing as UNIX C (which UNIX? version 7,
System V, 4.2. 4.3?).  Maybe you meant pcc (the portable C compiler)?

-- Marco Papa
   Felsina Software

ewhac@well.UUCP (02/02/87)

In article <958@tekred.TEK.COM> joels@tekred.TEK.COM (Joel Swank) writes:
>
>I recently ported a UNIX program to the Amiga. All went well execpt for
>one GURU that was caused by an index that was not initialized to zero
>at every entry to a subroutine. I put in an 'i=0;' and fixed it.
>later I was reading my C manual and it said that all 'auto' variables
>should be automaticly initialized to zero at every entry to the subroutine.
	   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>The UNIX C does this, but Manx does not. Is this a Manx bug?
>
>Joel Swank
>Tektronix, Redmond, Oregon

	Wrongo.  To wit:

--------
The C Programming Language, Kernighan & Ritchie, p. 82:

	"In the absence of explicit initialization, external and static
variables are guaranteed to be initialized to zero; automatic and register
variables have undefined (i.e. garbage) values."
--------
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Leo L. Schwab				ihnp4!ptsfa!well!ewhac
The Guy in The Cape				..or..
					well ---\
"Work FOR?  I don't work FOR		dual ----> !unicom!ewhac
anybody.  I'm just having fun."		hplabs -/       ("AE-wack")

flaps@utcsri.UUCP (Alan J Rosenthal) (02/03/87)

In article <958@tekred.TEK.COM> joels@tekred.UUCP writes:
>later I was reading my C manual and it said that all 'auto' variables
>should be automaticly initialized to zero at every entry to the subroutine.
>The UNIX C does this, but Manx does not. Is this a Manx bug?

As Matt pointed out, the initial value in this case is undefined (see the
middle of page 198 of K&R).

UNIX C does not do this.  However, when memory is allocated to a process in
the first place it is zeroed.  Therefore many things which are supposed to
contain "garbage" (such as uninitialized auto variables) in fact will contain
zero SOMETIMES.  Counting on this is stupid!  In addition, this is generally
not the case with micros, as the reason for this zeroing of memory is to
protect users from having other users see their memory contents just
deallocated.

(An example of a devious use possible on some mainframes if they didn't zero
memory (but not applicable to unix) is allocating a large amount of memory
right after someone logs in & looking through it to see if their password is
there.)

-- 

Alan J Rosenthal

UUCP: {backbone}!seismo!mnetor!utcs!flaps, ubc-vision!utai!utcs!flaps,
      or utzoo!utcs!flaps (among other possibilities)
ARPA: flaps@csri.toronto.edu
CSNET: flaps@toronto
BITNET: flaps at utorgpu