Hai,
When viewing threads of comp.lang.c, I came across with 'static
const char * const resultFileName = "param.txt";' . Here in this
thread, 'static const char * const resultFileName = "param.txt";' is
declared globally.
a) What is the use of declaring a global variable static?
b) Why in this thread they had use "const" the two times?
c) When mentionting as const, the variable we declared remains
constant. Why there is need for using static?
Kindly clear my doubts.
Thanks and Regards,
M.Sworna Vidhya. 5 2029
"sworna vidhya" <sw************@yahoo.co.in> wrote in message
news:46**************************@posting.google.c om... Hai,
When viewing threads of comp.lang.c, I came across with 'static const char * const resultFileName = "param.txt";' . Here in this thread, 'static const char * const resultFileName = "param.txt";' is declared globally.
a) What is the use of declaring a global variable static?
It causes the object to have internal linkage.
b) Why in this thread they had use "const" the two times?
It indicates that both the pointer and what it points
to are const.
const char *p; /* 1) non-const pointer to const char */
char const *p; /* 2) same as 1) */
char * const p; /* 3) const pointer to non-const char */
const char * const p; /* 4) const pointer to const char */
char const * const p; /* 5) same as 4) */
c) When mentionting as const, the variable we declared remains constant. Why there is need for using static?
'static' and 'const' are two separate concepts in C.
'const' prohibits modification of the object it qualifies.
When used at file scope, 'static' affects linkage.
When used at block scope, 'static' affects lifetime.
-Mike
sworna vidhya wrote: Hai,
When viewing threads of comp.lang.c, I came across with 'static const char * const resultFileName = "param.txt";' . Here in this thread, 'static const char * const resultFileName = "param.txt";' is declared globally.
a) What is the use of declaring a global variable static?
static prevents the variable from having external linkage.
In C, variables have scope and linkage, neither of which is called "global."
b) Why in this thread they had use "const" the two times?
Because two things are declared cont: the pointer and the thing pointed to.
c) When mentionting as const, the variable we declared remains constant. Why there is need for using static?
Already answered above.
Martin Ambuhl <ma*****@earthlink.net> wrote in message news:<c5************@ID-227552.news.uni-berlin.de>... sworna vidhya wrote: When viewing threads of comp.lang.c, I came across with 'static const char * const resultFileName = "param.txt";' . Here in this thread, 'static const char * const resultFileName = "param.txt";' is declared globally.
a) What is the use of declaring a global variable static?
static prevents the variable from having external linkage. In C, variables have scope and linkage, neither of which is called "global."
that is it is only accessible in the file it appears in.
<snip>
--
Nick Keighley
In <8a**************************@posting.google.com > ni***********@marconi.com (Nick Keighley) writes: Martin Ambuhl <ma*****@earthlink.net> wrote in message news:<c5************@ID-227552.news.uni-berlin.de>... sworna vidhya wrote:
> When viewing threads of comp.lang.c, I came across with 'static > const char * const resultFileName = "param.txt";' . Here in this > thread, 'static const char * const resultFileName = "param.txt";' is > declared globally. > > a) What is the use of declaring a global variable static?
static prevents the variable from having external linkage. In C, variables have scope and linkage, neither of which is called "global."
that is it is only accessible in the file it appears in.
In which case, calling it "global" is an oxymoron.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de Da*****@cern.ch (Dan Pop) wrote in message news:<c5**********@sunnews.cern.ch>... In <8a**************************@posting.google.com > ni***********@marconi.com (Nick Keighley) writes:Martin Ambuhl <ma*****@earthlink.net> wrote in message news:<c5************@ID-227552.news.uni-berlin.de>... sworna vidhya wrote:
> When viewing threads of comp.lang.c, I came across with 'static > const char * const resultFileName = "param.txt";' . Here in this > thread, 'static const char * const resultFileName = "param.txt";' is > declared globally. > > a) What is the use of declaring a global variable static?
static prevents the variable from having external linkage. In C, variables have scope and linkage, neither of which is called "global."
that is it is only accessible in the file it appears in.
In which case, calling it "global" is an oxymoron.
I'm not arguing I just wasn't sure the OP would understand terms
like "external linkage"
--
Nick Keighley This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jose luis fernandez diaz |
last post by:
Hi,
I am reading Stroustrup's book 'C++ Programming Language'. In the
10.4.9 section (Nonlocal Store) he says:
"A variable defined outside any function (that is global, namespace,
and class...
|
by: Thomas Matthews |
last post by:
Hi,
I'm getting linking errors when I declare a variable in the
global scope, but not inside a function. The declarations
are the same (only the names have been changed...).
class Book
{...
|
by: MLH |
last post by:
A97 Topic: If there is a way to preserve the values assigned to
global variables when an untrapped runtime error occurs? I don't
think there is, but I thought I'd ask.
During development, I'm...
|
by: MLH |
last post by:
I've read some posts indicating that having tons of GV's in
an Access app is a bad idea. Personally, I love GVs and I
use them (possibly abuse them) all the time for everything
imaginable - have...
|
by: Michael |
last post by:
Hi newsgroup,
as the subject indicates I am looking for an advice
using global variables. I am not if this problem is more
about style then C. If its wrong in thi group, sorry.
So I have a...
| |
by: Vishwanathan Raman |
last post by:
Hi
I have a declared a static DataSet object SOBJ in Global.asax.I also have a
localy defined DataSet LSOBJ in Global.asax which I am storing in Application
State.Is there any technical...
|
by: eoindeb |
last post by:
Sorry to ask another global variable question, but from reading other
posts I'm still not sure whether to use them or not.
I have a program with a set function that calls 4 other functions in...
|
by: CDMAPoster |
last post by:
About a year ago there was a thread about the use of global variables
in A97:
http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/fedc837a5aeb6157
Best Practices by Kang...
|
by: Sandman |
last post by:
I dont think I understand them. I've read the section on scope in the
manual inside out.
I'm running PHP 5.2.0 Here is the code I'm working on:
//include_me.php
<?php
$MYVAR = array();
global...
|
by: weaknessforcats |
last post by:
C++: The Case Against Global Variables
Summary
This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |