union bit (trunk only)
I'm pretty sure that some pre-standard compilers don't know how to
apply an initializer to a variable of type union. Unfortunately, I don't
have access to one to check. Fortunately, there's no need to explicitly
initialize `zeroany' since the default value is what we want--the first
field will be set to zero or null as appropriate (null in this case).
Strictly speaking, this isn't adequate; what if long is wider than a
pointer rather than narrower? Using `= {DUMMY}' didn't handle that case
either; the ordering of the union's fields controls which bits get stored.
As a practical matter, it should make no difference. As long as the code
reading a union accesses the same field as the code writing that union set
up in it, anything in extraneous bits should be irrelevant--except perhaps
when a debugger tries to format things. The whole issue has always been
implicitly based on the assumption that null pointers have all bits zero
in the first place; that's typical but not guaranteed.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* SCCS Id: @(#)decl.c 3.5 2005/11/19 */
|
||||
/* SCCS Id: @(#)decl.c 3.5 2006/07/10 */
|
||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
|
||||
@@ -194,8 +194,8 @@ NEARDATA struct obj *billobjs = (struct obj *)0;
|
||||
|
||||
/* used to zero all elements of a struct obj */
|
||||
NEARDATA struct obj zeroobj = DUMMY;
|
||||
/* used to zero out union any*/
|
||||
NEARDATA anything zeroany = DUMMY;
|
||||
/* used to zero out union any; initializer deliberately omitted */
|
||||
NEARDATA anything zeroany;
|
||||
|
||||
/* originally from dog.c */
|
||||
NEARDATA char dogname[PL_PSIZ] = DUMMY;
|
||||
|
||||
@@ -61,7 +61,7 @@ void
|
||||
zero_anything(any)
|
||||
anything *any;
|
||||
{
|
||||
(void) memset((genericptr_t)any, 0, sizeof(anything));
|
||||
*any = zeroany;
|
||||
}
|
||||
|
||||
boolean
|
||||
|
||||
Reference in New Issue
Block a user