Re: alternate to global variables
From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 09/17/04
- Next message: Alwyn: "Re: What is the ARM compiler?"
- Previous message: Chris \( Val \): "Re: Making a header to include other header (C++) Et Al."
- In reply to: Tom: "Re: alternate to global variables"
- Next in thread: Alwyn: "Re: alternate to global variables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/
- Next message: Alwyn: "Re: What is the ARM compiler?"
- Previous message: Chris \( Val \): "Re: Making a header to include other header (C++) Et Al."
- In reply to: Tom: "Re: alternate to global variables"
- Next in thread: Alwyn: "Re: alternate to global variables"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|