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

Re: To use global variables or no????



"Al Balmer" <albalmer@xxxxxxx> wrote in message 
news:6aib82dpi5as9vplv8oqt1mpcakig7ntr3@xxxxxxxxxx
> On Tue, 06 Jun 2006 19:01:27 +0100, John Devereux
> <jdREMOVE@xxxxxxxxxxxxxxxxxx> wrote:
>
>>Richard Heathfield <invalid@xxxxxxxxxxxxxxx> writes:
>>
>>> I can think of two reasons off-hand for using non-auto non-const 
>>> objects,
>>> one of which I don't like but am prepared to accept, and the other of 
>>> which
>>> I don't like but don't have any choice about accepting.
>>
>>I might be misunderstanding you, but don't some types of function need
>>to keep "static" state information?  E.g. functions like malloc?
>
> I may also be misunderstanding, but I often find static objects useful
> when writing access functions for opaque types.

Static data objects are useful when there is no better way to achieve the 
same desired result (typically, persistent state information that needs 
exactly one copy for the duration of program execution).  On the other hand, 
they (static data objects) often cause a lot more problems than they solve. 
A typical example is strtok().  Because strtok() maintains static 
information, calling strtok() from two different locations in your program 
can lead to subtle bugs.  The strtok_r() design is a much better design for 
that reason.

> -- 
> Al Balmer
> Sun City, AZ





Home | Main Index | Thread Index 121984 153788 328589 352113 397175 440114 477490 674162 772433 789381