Re: alternate to global variables

From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 09/17/04


Date: Fri, 17 Sep 2004 17:49:13 +0200

Tom wrote:

> > What are you unhappy with? Why are you looking for a better, safer
> > way? Are you having a specific problem?
>
> Safer. I don't want the data to get "stepped on."
>
>
> > In principle, that is how it is done in C. The only thing
> > would be: Put ListOfNodes, LastNode and all the functions
> > working on them into a seperate translation unit and make
> > ListOfNodes and LastNode static. But that's as much as you
> > can do in C to protect them from the outside world.
>
> I intended to do that anyway, so at least I know I'm on the right track.
> I was looking to see if there was any more "protection" I could do.

Once you declare the variables as 'static', their names will not be visible
outside the source-file in which they are declared.
This means that the data can only be altered if you explicitly give out a
pointer to it, or if a bug elsewhere causes random memory to be trashed.
The first can easily be checked with a review of the code (only one file
involved) and the other can not be prevented anyway.

>
> Thanks!
> Tom

Bart v Ingen Schenau

-- 
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/


Relevant Pages

  • Re: Templates and typedef
    ... >Is it possible to declare this as a type, ... You only have to use typename when using a member of a dependent type ... Tom ... C++ FAQ: http://www.parashift.com/c++-faq-lite/ ...
    (comp.lang.cpp)
  • Re: Newbie Question - Excel VBA
    ... Thanks Tom that sorted it. ... I was trying to declare the public variable ... inside a workbook module, and not in the general one... ... > workbook or userform module) outside any procedure. ...
    (microsoft.public.excel.programming)
  • Re: Gravity, Curvature vs Force
    ... "Tom Roberts" wrote in message ... >> Tom is well aware that neither he, nor his FAQ ever bothered to consider ... > In that article you claim Miller's resolution was 0.01 fringe. ... Besides, even if his resolution is 0.1 fringe, his results ...
    (sci.physics)
  • Re: Gravity, Curvature vs Force
    ... "Tom Roberts" wrote in message ... >> Tom is well aware that neither he, nor his FAQ ever bothered to consider ... > In that article you claim Miller's resolution was 0.01 fringe. ... Besides, even if his resolution is 0.1 fringe, his results ...
    (sci.physics.relativity)
  • Re: Algorithm Modes
    ... I agree with you entirely Tom - Schneier details further reasons in sect 5.7 ... My point was that "the group" should work on updating the FAQ with these ... It forces a decryption routine to be required. ...
    (sci.crypt)