bug-bash
[Top][All Lists]
Advanced

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

Re: ~60 global variables use by only one function in bash source


From: Chet Ramey
Subject: Re: ~60 global variables use by only one function in bash source
Date: Sat, 19 Jan 2019 17:02:35 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.3.3

On 1/18/19 6:06 PM, Peng Yu wrote:
> Hi,
> 
> I see these global or static variables (1st column) used only by one
> function (2nd column). Some are from bash, some are from the libraries
> that bash depends.

OK. You've done the first part by compiling a list. Now you have to perform
the analysis.

> 
> It seems to be problematic to declare variables global/static but only
> to use them in one function. Should these variables be made local?

It's not problematic per se. You have to look at what the variables do.
So start by eliminating

1) variables that are global because system libraries require them;

2) variables that are global because they are intended to be modified by
   applications and so are declared in public header files;

3) variables that reflect values set in user startup or config files, or
   correspond to flags or invocation options;

4) variables that you included incorrectly and are actually used in

   multiple files (e.g., this_shell_function, vi_insertion_keymap,
   dont_save_function_defs, from_return_trap, build_version,
   terminate_immediately, sh_syntabsiz, optflags, release_status,
   bash_copyright, bash_license, and so on).

Then you have a manageable list that you can analyze. There probably are
a few variables that aren't used anymore. A good optimizing compiler will
remove those. There are also a few variables there for my use when
debugging.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/



reply via email to

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