By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,667 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,667 IT Pros & Developers. It's quick & easy.

Pass by Reference Function Question

P: n/a
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope. The global
variables and global functions are hidden to prevent from accessing by the
programmers. All global functions share global variables.
Only very few global functions are allowed to be reusability for the
programmers to use. Few global functions access most hidden functions
during the time execution.
My question is -- do you think that pass by reference is really
necessary? Pass by reference is necessary unless you want to reuse function
with the choice of global / local variables. Please advise.

--

Yours Truly,
Bryan Parkoff
Jun 27 '08 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Bryan Parkoff wrote:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope. The
global variables and global functions are hidden to prevent from
accessing by the programmers. All global functions share global
variables. Only very few global functions are allowed to be
reusability for the programmers to use. Few global functions access
most hidden functions during the time execution.
That sounds like a very bad design. No offence.
My question is -- do you think that pass by reference is really
necessary? Pass by reference is necessary unless you want to reuse
function with the choice of global / local variables. Please advise.
You need a good book on design and some time to digest it. I am not
really sure what to recommend. "Advanced C++" by Coplien? Dated.
"Multiparadigm Design for C++" by him? Maybe. "Modern C++ Design"
by Alexandrescu? "Large-Scale C++ Software Design" by Lakos? <shrug>

If you want more OOD theory, look for Grady Booch (and ask in the
comp.object newsgroup).

Most of what I've read and been taught says that global data should be
avoided. So, if you start with that premise, passing objects to your
functions (either by pointer or by reference) becomes a necessity.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #2

P: n/a
On Apr 11, 3:24 pm, "Bryan Parkoff" <nos...@nospam.comwrote:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope.
OK
The global
variables and global functions are hidden to prevent from accessing by the
programmers.
Then they aren't global are they?
What means did you use to "hide" them?

All global functions share global variables.
OK
Only very few global functions are allowed to be reusability for the
programmers to use.
What do you mean?
You have global functions that you don't want anyone to call? They
probably shouldn't be global then.

Few global functions access most hidden functions
during the time execution.
I thought the global functions were hidden themselves from what you
said earlier...
So, you have global "hidden" functions (I don't know how) calling
other global "hidden" functions?

My question is -- do you think that pass by reference is really
necessary?
Necessary for what?
What are you trying to do? show some source code.

Pass by reference is necessary unless you want to reuse function
with the choice of global / local variables.
What? I don't know what you are talking about, but no. There is no
requirement to pass by reference based on global functions or
variables or lack thereof.
Jun 27 '08 #3

P: n/a
On Apr 11, 3:24 pm, "Bryan Parkoff" <nos...@nospam.comwrote:
> I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope.

OK
I see you understand now.
>The global
variables and global functions are hidden to prevent from accessing by
the
programmers.

Then they aren't global are they?
What means did you use to "hide" them?
Well, you can make one of two choice -- global object or local object.
The local object is ideal for class. You can always bind local variable and
local function inside class. I have chosen to use global object. I agree
that global variable should be avoided unless you put global object inside
namespace for better readability. Global object has concern of performance
issue than local object like class. Anyway...
> All global functions share global variables.

OK
> Only very few global functions are allowed to be reusability for the
programmers to use.

What do you mean?
You have global functions that you don't want anyone to call? They
probably shouldn't be global then.
You call public global function. Then public global function is in turn
to call hidden global functions. I do not want the programmers to see
hidden global functions and they are allowed to use global object by running
public global function.
>Few global functions access most hidden functions
during the time execution.

I thought the global functions were hidden themselves from what you
said earlier...
So, you have global "hidden" functions (I don't know how) calling
other global "hidden" functions?

>My question is -- do you think that pass by reference is really
necessary?

Necessary for what?
What are you trying to do? show some source code.

>Pass by reference is necessary unless you want to reuse function
with the choice of global / local variables.

What? I don't know what you are talking about, but no. There is no
requirement to pass by reference based on global functions or
variables or lack thereof.
Let me give you sample code. It helps you to understand better. You
can see that pass by reference is not necessary because all hidden functions
share global variable.

// Global object
namespace Object
{
static int a = 0; // hidden global variable
static int b = 0; // hidden global variable
static int c = 0; // hidden global variable

static void Modify1 (void); // hidden global function
static void Modify2 (void); // hidden global function
static void Modify3 (void); // hidden global function
void Run_Object (void); // public global function

void Modify1 (void)
{
a += 2;
b += 4;
c = a * b;
}

void Modify2 (void)
{
a *= 5;
b *= 10;
c = a - b;
}

void Modify3 (void)
{
a = b / c;
b = 0;
c = 0;
}

void Run_Object (void)
{
Modify1();
Modify2();
Modify3();
}
}

// end of header

#include "object.h" // above code

int main (void)
{
// do something...
Object::Run_Object(); // Run fine for all hidden functions.

Object::Modify1 (); // Error Time Compile -- you can't access hidden
global functions.
a = 5; // Time Compile runs fine unless you use global variable -- a
outside main function on this source like main.cpp
Object::a = 10; // Error Time Compile -- you can't access hidden global
variable
return 0;
}

You can see that namespace is ideal for readability because sometimes
global variable has the same name in both source codes. It guards against
overwritten accidently.
Please advise.

Yours Truly,
Bryan Parkoff
Jun 27 '08 #4

P: n/a
On Apr 11, 5:00 pm, "Bryan Parkoff" <nos...@nospam.comwrote:
On Apr 11, 3:24 pm, "Bryan Parkoff" <nos...@nospam.comwrote:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope.
OK

I see you understand now.
The global
variables and global functions are hidden to prevent from accessing by
the
programmers.
Then they aren't global are they?
What means did you use to "hide" them?

Well, you can make one of two choice -- global object or local object.
The local object is ideal for class. You can always bind local variable and
local function inside class. I have chosen to use global object. I agree
that global variable should be avoided unless you put global object inside
namespace for better readability. Global object has concern of performance
issue than local object like class. Anyway...
All global functions share global variables.
OK
Only very few global functions are allowed to be reusability for the
programmers to use.
What do you mean?
You have global functions that you don't want anyone to call? They
probably shouldn't be global then.

You call public global function. Then public global function is in turn
to call hidden global functions. I do not want the programmers to see
hidden global functions and they are allowed to use global object by running
public global function.
Few global functions access most hidden functions
during the time execution.
I thought the global functions were hidden themselves from what you
said earlier...
So, you have global "hidden" functions (I don't know how) calling
other global "hidden" functions?
My question is -- do you think that pass by reference is really
necessary?
Necessary for what?
What are you trying to do? show some source code.
Pass by reference is necessary unless you want to reuse function
with the choice of global / local variables.
What? I don't know what you are talking about, but no. There is no
requirement to pass by reference based on global functions or
variables or lack thereof.

Let me give you sample code. It helps you to understand better. You
can see that pass by reference is not necessary because all hidden functions
share global variable.

// Global object
namespace Object
{
static int a = 0; // hidden global variable
static int b = 0; // hidden global variable
static int c = 0; // hidden global variable

static void Modify1 (void); // hidden global function
static void Modify2 (void); // hidden global function
static void Modify3 (void); // hidden global function
void Run_Object (void); // public global function

void Modify1 (void)
{
a += 2;
b += 4;
c = a * b;
}

void Modify2 (void)
{
a *= 5;
b *= 10;
c = a - b;
}

void Modify3 (void)
{
a = b / c;
b = 0;
c = 0;
}

void Run_Object (void)
{
Modify1();
Modify2();
Modify3();
}

}

// end of header

#include "object.h" // above code

int main (void)
{
// do something...
Object::Run_Object(); // Run fine for all hidden functions.

Object::Modify1 (); // Error Time Compile -- you can't access hidden
global functions.
a = 5; // Time Compile runs fine unless you use global variable -- a
outside main function on this source like main.cpp
Object::a = 10; // Error Time Compile -- you can't access hidden global
variable
return 0;

}

You can see that namespace is ideal for readability because sometimes
global variable has the same name in both source codes. It guards against
overwritten accidently.
Please advise.

Yours Truly,
Bryan Parkoff

Oh my goodness where to begin...

Do not write implementation in header files. Write it in .cpp files
Your source is obviously not what you ran, because the compiler gives
no such error: "you can't access hidden global variable"

Yes, passing anything at all, by reference or value, is not necessary
in this example code, because the variables in question are global to
the namespace in which the functions that use them, belong to. Passing
them by reference is not necessary because they are also primitive
types. Passing them by reference is also not necessary because
modifications made to them inside the function change the variables
values outside the function, since they are global. Had they been UDTs
passing by reference or const reference may have been preferable. Had
they belonged to another object or been declared within function body,
passing by reference may have been necessary.

I see no reason at all that this entire namespace can't be neatly made
into a class. Why are you making everything global exactly?

Also, are you sure you know what you are doing with the "static"
keyword here?

Jun 27 '08 #5

P: n/a
Bryan Parkoff wrote:
[..]
Let me give you sample code. It helps you to understand better. You
can see that pass by reference is not necessary because all
hidden functions share global variable.

// Global object
namespace Object
{
static int a = 0; // hidden global variable
static int b = 0; // hidden global variable
static int c = 0; // hidden global variable

static void Modify1 (void); // hidden global function
static void Modify2 (void); // hidden global function
static void Modify3 (void); // hidden global function
You keep using the word "hidden" as if it is a mantra. How are
those variables and functions *hidden*? I can see them here
just fine, and so can a compiler.
void Run_Object (void); // public global function

void Modify1 (void)
{
a += 2;
b += 4;
c = a * b;
}

void Modify2 (void)
{
a *= 5;
b *= 10;
c = a - b;
}

void Modify3 (void)
{
a = b / c;
b = 0;
c = 0;
}

void Run_Object (void)
{
Modify1();
Modify2();
Modify3();
}
}

// end of header

#include "object.h" // above code

int main (void)
Please drop those "void" in parentheses. Looks so C, so last
century. Don't put anything where nothing is expected.
{
// do something...
Object::Run_Object(); // Run fine for all hidden functions.
I have a problem with your comments. I don't get the errors where
you claim to have some, and I do get the error on the 'a = 5' line
where you say "runs fine"...
Object::Modify1 (); // Error Time Compile -- you can't access
hidden global functions.
a = 5; // Time Compile runs fine unless you use global variable --
a outside main function on this source like main.cpp

I don't get the "fine" above, 'a' is undefined.
Object::a = 10; // Error Time Compile -- you can't access hidden
global variable
I get no error.
return 0;
}

You can see that namespace is ideal for readability because
sometimes global variable has the same name in both source codes. It
guards against overwritten accidently.
Huh?
Please advise.
What is it you'd like us to advise on? Could you please put it in
a form of a question?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #6

P: n/a
"Christopher" <cp***@austin.rr.comwrote in message
news:8b**********************************@8g2000hs u.googlegroups.com...
On Apr 11, 5:00 pm, "Bryan Parkoff" <nos...@nospam.comwrote:
On Apr 11, 3:24 pm, "Bryan Parkoff" <nos...@nospam.comwrote:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope.
OK

I see you understand now.
>The global
variables and global functions are hidden to prevent from accessing by
the
programmers.
Then they aren't global are they?
What means did you use to "hide" them?

Well, you can make one of two choice -- global object or local
object.
The local object is ideal for class. You can always bind local variable
and
local function inside class. I have chosen to use global object. I
agree
that global variable should be avoided unless you put global object
inside
namespace for better readability. Global object has concern of
performance
issue than local object like class. Anyway...
> All global functions share global variables.
OK
> Only very few global functions are allowed to be reusability for
the
programmers to use.
What do you mean?
You have global functions that you don't want anyone to call? They
probably shouldn't be global then.

You call public global function. Then public global function is in
turn
to call hidden global functions. I do not want the programmers to see
hidden global functions and they are allowed to use global object by
running
public global function.
>Few global functions access most hidden functions
during the time execution.
I thought the global functions were hidden themselves from what you
said earlier...
So, you have global "hidden" functions (I don't know how) calling
other global "hidden" functions?
>My question is -- do you think that pass by reference is really
necessary?
Necessary for what?
What are you trying to do? show some source code.
>Pass by reference is necessary unless you want to reuse function
with the choice of global / local variables.
What? I don't know what you are talking about, but no. There is no
requirement to pass by reference based on global functions or
variables or lack thereof.

Let me give you sample code. It helps you to understand better. You
can see that pass by reference is not necessary because all hidden
functions
share global variable.

// Global object
namespace Object
{
static int a = 0; // hidden global variable
static int b = 0; // hidden global variable
static int c = 0; // hidden global variable

static void Modify1 (void); // hidden global function
static void Modify2 (void); // hidden global function
static void Modify3 (void); // hidden global function
void Run_Object (void); // public global function

void Modify1 (void)
{
a += 2;
b += 4;
c = a * b;
}

void Modify2 (void)
{
a *= 5;
b *= 10;
c = a - b;
}

void Modify3 (void)
{
a = b / c;
b = 0;
c = 0;
}

void Run_Object (void)
{
Modify1();
Modify2();
Modify3();
}

}

// end of header

#include "object.h" // above code

int main (void)
{
// do something...
Object::Run_Object(); // Run fine for all hidden functions.

Object::Modify1 (); // Error Time Compile -- you can't access hidden
global functions.
a = 5; // Time Compile runs fine unless you use global variable -- a
outside main function on this source like main.cpp
Object::a = 10; // Error Time Compile -- you can't access hidden
global
variable
return 0;

}

You can see that namespace is ideal for readability because sometimes
global variable has the same name in both source codes. It guards
against
overwritten accidently.
Please advise.

Yours Truly,
Bryan Parkoff
Christopher,
Oh my goodness where to begin...
Thank you for your comment.
Do not write implementation in header files. Write it in .cpp files
Your source is obviously not what you ran, because the compiler gives
no such error: "you can't access hidden global variable"
I agree. I always declare variables and functions in the header code
and I always define variable and functions in the source code. It would
help to debug a lot better. After you complete designing both header code
and source code, you will be able to create static library or DLL library.
Then, source code is not necessary. You can always use header code and it
will access to "LIB" or "DLL" file at compile time.
Yes, passing anything at all, by reference or value, is not necessary
in this example code, because the variables in question are global to
the namespace in which the functions that use them, belong to. Passing
them by reference is not necessary because they are also primitive
types. Passing them by reference is also not necessary because
modifications made to them inside the function change the variables
values outside the function, since they are global. Had they been UDTs
passing by reference or const reference may have been preferable. Had
they belonged to another object or been declared within function body,
passing by reference may have been necessary.
I understand.
I see no reason at all that this entire namespace can't be neatly made
into a class. Why are you making everything global exactly?
According to my performance test, global variables and global functions
are running faster than local variable and local function inside class. You
don't need to use a pointer to access global variable or global function.
You create a class. You define local variable and local function inside
class. The class requires a pointer to access local variable or local
function inside class. It may be slow because extra x86 instruction has to
be added to read memory address and then locate value in the memory.
Also, are you sure you know what you are doing with the "static"
keyword here?
Yes, I understand "static" keyword. It has two different definitions.
If you have same variable name on the global scope and local scope, you put
static inside function. Local variable inside function can modify global
variable outside of function. This way, you exit function, you won't lose
local variable to be placed in global variable. It is fine. I don't use
this feature.
Another definition for static is internal linkage. All global variables
and global functions have static keyword so they are inside internal
linkage. The global variable and global function using internal linkage on
the one header code is never available to all source codes unless you want
to use public function (you put extern keyword for public) in turn to access
hidden function. It is good design.
Please tell me what you think how to design object better -- use global
object for performance reason or local object for readability and reduce
bugs.

Yours Truly,
Bryan Parkoff
Jun 27 '08 #7

P: n/a
Bryan Parkoff asked:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline.
Ewww. Don't do that. If these functions are all doing nearly
the same thing (as I very much suspect), replace those 4000
functions with maybe 7 or 13 or 21 functions taking arguments
(passed by value or by reference, maybe returning a value and
maybe not, as the problem demands) to configure their behavior.

The whole idea of functions is STRUCTURE. That means top-level
functions call mid-level functions, and mid-level functions
call bottom-level functions. Having 4000 tiny, nearly-identical
bottom-level functions is a design nightmare.
I define variables and functions in the global scope.
Don't define variables at the global scope. Period.
The global variables and global functions are hidden to prevent
from accessing by the programmers. All global functions share
global variables.
I don't see how you can make global variables "hidden",
unless you make them file-static, so that only one translation
unit sees them.

If you need data hiding (encapsulation), define your objects
either on the stack (local, "auto") in functions, or dynamically
(using new and delete).

You can still allow one function to have read/write access to
local variables in another function by passing arguments by
non-const reference, like so:

void function2 (double & asdf) // NON-CONST REF!!!!!
{
asdf *= 2.0; // alters "trouble" in function1 below
return;
}

int function1 (void)
{
double trouble = 47;
function2(trouble); // double trouble (pardon pun)
std::cout << trouble << std::endl; // prints 94
return 42;
}
Only very few global functions are allowed to be reusability for the
programmers to use. Few global functions access most hidden functions
during the time execution.
My question is -- do you think that pass by reference is really
necessary? Pass by reference is necessary unless you want to reuse function
with the choice of global / local variables. Please advise.
Passing by non-const reference is the only way I know of that
one function can alter local variables in another function.
I use it a lot in my C++ programming. I try for ZERO global
variables. I often don't quite make it, electing to have
2 or 3 global variables, if they truly are used by a lot of
different functions. But that's really just laziness on my
part; it *could* all be done with non-const refs instead.

--
Cheers,
Robbie Hatley
lonewolf aatt well dott com
www dott well dott com slant user slant lonewolf slant
Jun 27 '08 #8

P: n/a
Robbie Hatley wrote:
Bryan Parkoff asked:
> I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline.

Ewww. Don't do that. If these functions are all doing nearly
the same thing (as I very much suspect), replace those 4000
functions with maybe 7 or 13 or 21 functions taking arguments
(passed by value or by reference, maybe returning a value and
maybe not, as the problem demands) to configure their behavior.
Where did he say they were doing nearly the same thing?

There's nothing wrong with using lots of small function if they make the
code clearer.

--
Ian Collins.
Jun 27 '08 #9

P: n/a
>> static int a = 0; // hidden global variable
>
Both a named namespace and file scope rarely makes sense.

To declare an identifier with external binding and
file scope, in C++, an anonymous namesspace is used:

namespace { int a = 0; }

»static« was used in C for this purpose, but is
obsolecent in C++.
If you write C source code, you always want most functions to be
invisible inside one header and source code using internal linkage. It is
best to guard these functions. It is ideal when you make to design a chip.
You do not want people to do reverse engineering to see inside chip and draw
schematic.
Then, why do you claim **static** keyword to be obsolete for both global
variables and global functions? I ask you please provide me an example of
your source code in C++. Please do not tell me if I have to use class. I
do not want to use a pointer to access memory address and locate variable
and function inside class. It is slower than global function without
pointer according to my performance test.
It is why I try to find some ways how to design object better on global
slope instead of local slope like class.
It is a bad practice to write a huge function with about 50 - 1,000
lines. It is too complex and difficult time to do debugging. Write very
small hundred or thousand functions with 5 - 20 lines. Be very simple
instead of complex. Add inline to all small functions. You can always put
some small sub-functions into one function. The C++ Compiler can decide to
put piece of sub-functions together into one big function. It can decide to
use peformance or small codes without inline.
Maybe, you should use **static** inside function body. This way, you
always avoid modifying global variable. Use local variable to test inside
function body. You decide to store local variable into global variable by
adding static. I think pass by reference is not good idea because you might
accidently overwrite global variable unless you know sure to be avoided.

Yours Truly,
Bryan Parkoff
Jun 27 '08 #10

P: n/a
"Bryan Parkoff" <no****@nospam.comwrote in
news:47***********************@roadrunner.com:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope. The
global variables and global functions are hidden to prevent from
accessing by the programmers. All global functions share global
variables.
Only very few global functions are allowed to be reusability for
the
programmers to use. Few global functions access most hidden functions
during the time execution.
My question is -- do you think that pass by reference is really
necessary? Pass by reference is necessary unless you want to reuse
function with the choice of global / local variables. Please advise.
Parameter pass by reference is usually discussed as opposed to passing by
value, but it seems you are discussing it as opposed to avoiding any
parameters at all (note also that passing by reference might be slower
for small parameter types than passing by value).
That said, if your program works fine with only global variables, then
this shows:

- there can be only 1 instance of data state at any time
- your functions are not reentrant
- your functions are not usable in a multithreaded environment

In other words, the problem your program solves appears to be very
simple. The C++ language was invented for dealing with much more
complicated problem domains. For starters, different object states are
commonly encapsulated in classes and multiple instances (objects) of a
given class are created at the same time.

In essence, I think your question shold be translated to:

"My program solves a very simple real life problem and does it fine. Is
it necessary to use any more complicated methods designed for more
complicated software architectures in my simple program?"

Answering this question is easy (and honestly there seems to be no need
to use C++ language at all!), but the real question is different: do you
want to extend your program to do a bit more or a bit differently in the
future?

HTH
Paavo
Jun 27 '08 #11

P: n/a
Bryan Parkoff wrote:
>>> static int a = 0; // hidden global variable

Both a named namespace and file scope rarely makes sense.

To declare an identifier with external binding and
file scope, in C++, an anonymous namesspace is used:

namespace { int a = 0; }

»static« was used in C for this purpose, but is
obsolecent in C++.

If you write C source code, you always want most functions to be
invisible inside one header and source code using internal linkage. It is
best to guard these functions. It is ideal when you make to design a
chip. You do not want people to do reverse engineering to see inside chip
and draw schematic.
Then, why do you claim **static** keyword to be obsolete for both
global
variables and global functions?
Because for this you use anonymous namespaces, as multiple people have
already pointed out.
I ask you please provide me an example of
your source code in C++. Please do not tell me if I have to use class. I
do not want to use a pointer to access memory address and locate variable
and function inside class. It is slower than global function without
pointer according to my performance test.
You keep repeating that, but have you actually really tried it?

The following code:
class dummy {
public:
int a;
int b;
void set() { a = 5; b = 6; };
};
namespace {
int a;
int b;
dummy c;
};
void f1()
{
a = 5;
b = 6;
}
void f2()
{
c.set();
}

produces on IA32 with g++4.2 -O3 -Wall -fomit-frame-pointer:

_Z2f1v:
movl $5, _ZN37_GLOBAL__N_static.C_00000000_D9D9A4DE1aE
movl $6, _ZN37_GLOBAL__N_static.C_00000000_D9D9A4DE1bE
ret

_Z2f2v:
movl $5, _ZN37_GLOBAL__N_static.C_00000000_D9D9A4DE1cE
movl $6, _ZN37_GLOBAL__N_static.C_00000000_D9D9A4DE1cE+4
ret

That is exactly the same code for the "global variables" version and
the "class" version. Of course, if you don't use inline methods, there will
be use of a this pointer, but I have a hard time imagining an application
where this makes any significant difference.

And if I understand the question in your first post (which I doubt): then it
will be better to only pass *one* "this" pointer than references (which are
probably implemented as pointers) to *multiple* variables. Just use
classes.
Jun 27 '08 #12

P: n/a
Stefan Ram wrote:
"Bryan Parkoff" <no****@nospam.comwrites:
>>»static« was used in C for this purpose, but is
obsolecent in C++.
Then, why do you claim **static** keyword to be obsolete for both
global

In C++, »static« is only obsolescent if it is used to indicate
internal linkage, because in C++, an anonymous namespace is
intended to be used for this purpose.
That is simply not true. Items declared in an anonymous namespace
have *external linkage*. It's the name (which is supposedly mangled
in an undocumented way) that makes them impossible to be referred to
from another module, not the absence of an external name. If you
want to hide the name altogether, you need to declare the object
_static_, which will give it a local name.
Other uses of »static« are not deemed obsolescent.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 27 '08 #13

This discussion thread is closed

Replies have been disabled for this discussion.