This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, gfortran] Fix trailing whitespace in getenv ...


On Mon, Aug 30, 2004 at 02:05:28PM -0700, Steve Kargl wrote:
> The attached patch removes trailing whitespace from the 
> the variable NAME prior to the call to getenv.

A big thanks to Steve for volunteering to clean up my mess.

>  BTW, g77
> can't handle an environmental variable with a space in the
> variable name.

Nice. Now we can brag that gfortran implements (some) g77 intrinsics
better than g77 itself! ;-)

Well, to the point. *Disclaimer* I don't have the source here at work,
so this is from memory.

As you know, the name_nt array is a copy of the name array with a '\0'
added at the end so that the libc getenv can find the end of the
string. Now, C99 allows variable declarations after executable
statements in a function. Thus, name_nt can be declared after the
whitespace has been counted, saving some stack space (gcc allocates
VLA:s on the stack). E.g. if someone calls getenv with a 1000
character string containing 'HOME' and the rest whitespace, name_nt
would be only 5 characters and not 1001.

Does this sound reasonable or did I forget some crucial detail?


-- 
Janne Blomqvist


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]