help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug(s) in 2.5.19 skel.c


From: Hans-Bernhard Broeker
Subject: Re: bug(s) in 2.5.19 skel.c
Date: Mon, 16 Sep 2002 12:07:21 +0200 (MET DST)

On Sun, 15 Sep 2002, Bruce Lilly wrote:

> A simpler and more effective alternative (since) only a few elements
> of the struct need to be initialized to something other thsn zero)
> would be either:

> 1. use calloc rather than malloc
> or
> 2. use memset() after malloc.

No, please don't rely on those, if possible.  Unless all the variables in
a struct are unsigned chars, calloc() or memset() do *not* guarantee
proper initialization to zero.  Not for code that wants to be as portable
as remotely possible, at least.

For situations where struct initialization can't be used reliably (e.g.
automatic variables), use struct assignment or memcpy the contents of a
statically initialized 'default values' struct instead.

This may feel awkward, but for 100% portability, it's the only way, short
of initializing everything by hand.

As to creating the list of globals: did you consider using a tool like
'cscope' to that end?  'cscope -kL1' should list all functions and global
variables, and it's not overly hard to get rid of the functions, either.

-- 
Hans-Bernhard Broeker (address@hidden)
Even if all the snow were burnt, ashes would remain.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]