Re: confused about global namespace and scope

From: Jonathan Wood (jwood_at_softcircuits.com)
Date: 06/19/04


Date: Sat, 19 Jun 2004 15:37:47 -0600

You have control over your "file structure" in VC++ as well. It's just that
you are using Wizards to create a number of files for you. Files created
automatically are done a certain way, but you can certainly change them if
you want.

If you want a separate header for your global variables, you are free to
create one. Personally, I avoid too many global variables in a C++ app. Not
very OOP you understand.

Again, Windows works a certain way and you are free to do everything from
scratch if you prefer. However, you will save a lot of time if you have the
VC Wizards do them for you. But you are comparing apples and oranges. You
are comparing a UNIX project that you write from scratch with a Windows
project that is created by wizards to utilize a large application framework.
Perhaps you should code a couple of Windows apps from scratch to see what is
going on under the hood. Windows applications use WinMain instead of main.

-- 
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
"Tony B" <TonyB@discussions.microsoft.com> wrote in message
news:7C8AAC08-6529-46C3-8D7E-26755C7740B0@microsoft.com...
> Well in UINX I had total control over my file structure and could put
anything where I wanted.  Well within reason..  I usually am a bit more
modular and would have a separate header for all my global variables and
include them just before the main function. But I am not sure this would
work in VC++ mainly because I am not really sure how the flow for how it
sets things up.  In UNIX I would do all that from scratch and know how the
flow went, though I have never coded any really big programs.  I can do all
the little "exercises" without much problem it is just when I go off on a
tangent and try to be creative I have issues because I guess I really don't
truly understand how Microsoft's default classes/library's interact.  Part
of the problem is I haven't really coded in many years and want to get back
into the game.  I have taken a couple classes and all they do is repeat all
the standard examples MS does( or they are real close).  When I show the
teacher an example of something I would like to try and do the standard
comment is "Well I have never tried to do that so I am not sure how it would
work."  What I really need to do is find someone who knows the in's and out'
s and hang with them for a couple hours and ask all those really stupid
question's then I will get a clue and move on.  I use to be fairly good at
this...  Guess I am a bit old school and all the automated "helping" it
doing nothing but giving me a headache.
>
> "Jonathan Wood" wrote:
>
> > This has nothing to do with UNIX or VC++. These are standard C++ issues.
> >
> > You can declare it in any source file. If you declare it in a header
file,
> > then the variable will be declared repeatedly for each source file that
> > includes that header file. You could also add an entry in a header file
that
> > references but does not declare that variable. Loopup extern.
> >
> > Again, this has absolutely nothing to do with UNIX or VC++. How did you
do
> > it in UNIX?
> >
> > -- 
> > Jonathan Wood
> > SoftCircuits
> > http://www.softcircuits.com
> > Available for consulting: http://www.softcircuits.com/jwood/resume.htm
> >
> > "Tony B" <Tony B@discussions.microsoft.com> wrote in message
> > news:17CC0BFE-0807-4883-A738-B1B71716EB84@microsoft.com...
> > > I didn't have problems with this in UNIX but VC++ is a different
matter.
> > Where do I declare a global variable like long A = 0;  I would have
thought
> > stdafx.  But regardless of where I have declared the variable both
classes
> > that I call it from do not see it as being part of the "normal"
namespace.
> > I have also tried declaring a namespace but getting access to it hasn't
work
> > as well.  So I guess my question is how do you get outside "int main()"
to
> > make your global declarations in VC++?  The help files are clear on how
to
> > use it just not where to put it in the scheme of things.
> > >
> >
> >
> >


Relevant Pages

  • Re: Scope of variables
    ... declare the variables in the function signature (function "header line"). ... print param # the value passed to the function ... # parameter list (hides global variables with the ...
    (comp.lang.awk)
  • Re: static library problems
    ... Do not declare variables in header files. ... variable itself must be declared in a .cpp file. ... >If i want to use this string in other modules, i just need include the header, i need not link this static lib. ...
    (microsoft.public.vc.mfc)
  • Re: Variables and scope ? !!!!
    ... without seeing the project but i no professional vba programmer but would ... > global -- available to all code in the application, declared in the header ... > a) Declare the variable, in the header of an ordinary module ... Global variables are, in general, bad practice. ...
    (microsoft.public.word.vba.general)
  • Re: Exported function mangaled name
    ... extern "C" { ... You have otherwise defined a function unrelated to the header ... You have to declare the function the same way in your .cpp file as in your .h file ... #define LIBSPEC __declspec ...
    (microsoft.public.vc.mfc)
  • RE: Static and Global Variables
    ... the top of a standard module using Dim instead of Public is visible only ... the major problem with Global variables is that any unhandled error ... a better technique is to use a Static function. ... I often declare public variables in a standard module. ...
    (microsoft.public.access.modulesdaovba)

Loading