www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/25/18:46:51

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Funny thing with _fixpath
Date: Wed, 25 Feb 1998 22:12:21 +0100
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 39
Message-ID: <34F48935.29EC552B@LSTM.Ruhr-UNI-Bochum.De>
References: <01bd41f7$4b2b5320$cd2f86c2 AT pieter>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Pieter van Ginkel wrote:
> 
> Because you don't know what the size of the string will be, you have two
> choises. The first is what you did ('char fixed_name[MAXDIR]') and the other
> is something you can use for a lot of other things. This is useing a global
> buffer. Just put something like ('char global_buffer[4096]') at the top of
> your program and you can use this in all kinds of functions. (You can also
> do this in every function.) The only problem you can have is that it is
> possible that you use the buffer in a function that is called by a function
> that uses the buffer, but if you take good care in writing your functions,
> it shouldn't be a problem.

I think you should _not_ do that. In fact, I think one should
avoid global variables like the plague, as they will hit you
with funny, subtle errors whenever you expect them least. In
this particular case, the stack is the perfect place
for a temporary variable. Something like

...
char tmp[MAXDIR];
  _fixedpath(foo, tmp);
  return (strdup(tmp));
}
is probably the best solution.
  
-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019