Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Why using the new keyword at all for memory allocation?

Reply
Thread Tools

Re: Why using the new keyword at all for memory allocation?

 
 
PencoOdStip@gmail.com
Guest
Posts: n/a
 
      05-23-2007
By the way.

Let's say i want this variable to be acessible in all functions.To be
global.

By alocating it like that in memory i will have acess to it from all
functions right? Like that it will be global???

Is there other way of making variables global?

 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      05-24-2007
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> By the way.
>
> Let's say i want this variable to be acessible in all functions.To be
> global.
>
> By alocating it like that in memory i will have acess to it from all
> functions right? Like that it will be global???
>
> Is there other way of making variables global?


To make a variable, any variable, global to all functions in a .cpp file,
simply declare it ouside of any function.

To make a variable, any variable, global to all compiliation units (other
..cpp files as well) in a header file, or other means, declare the varaible
as extern and then in one, and only one, .cpp file declare the variable
normally.

(Untested code)

MyProg.cpp:

int proba[5]
int* probb;

void Foo()
{
// Foo can "see" proba and probb
}

int main()
{
probb = new int[10];

// main can "see" proba and probb
}

-----------------------------------------

MyOtherFile.cpp:

extern* probb;

void Bar()
{
// Bar can "see" probb, but not proba.
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why using the new keyword at all for memory allocation? PencoOdStip@gmail.com C++ 6 05-25-2007 01:26 PM
RE: keyword checker - keyword.kwlist Hamilton, William Python 4 05-13-2007 06:31 AM
keyword checker - keyword.kwlist tom@finland.com Python 6 05-10-2007 04:53 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Re: Why does using keyword require a new scope? Herman Eldering ASP .Net 0 08-23-2003 11:32 PM



Advertisments