Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug with unset variables



On Wed, Nov 11, 2020 at 6:20 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> On 11/11/20, Felipe Contreras <felipe.contreras@xxxxxxxxx> wrote:

> > That being said, the most similar to shell's "declare var" in C is
> > "char *var" which defaults to null on most systems.
>
> This is certainly not true, just for the record. Variables in global
> or static scope are initialized to 0 regardless of type, whereas
> others are uninitialized (meaning they contain garbage, not that they
> magically know that they haven't been assigned to).

The C standard says accessing an uninitialized variable results in
*undefined* behavior, it doesn't say the variable *must* contain
garbage. The variable *may* contain garbage, but not necessarily so.

However, "static char *var" is *always* initialized to null.

Either way, what *never* happens is var pointing to an empty string.

-- 
Felipe Contreras




Messages sorted by: Reverse Date, Date, Thread, Author