473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

static array

hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric

Jul 28 '06 #1
11 3174
di**********@yahoo.com wrote:
hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric
In what context?

The same rules apply for a character array as for any other variable.

If the array is in a compilation unit and you don't want it to be
visible elsewhere, you declare it static to avoid polluting the global
namespace with the array's name.

If the array has function scope and you wish the value to be retained
between calls, you would declare it static.

--
Ian Collins.
Jul 28 '06 #2

di**********@yahoo.com wrote:
hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric
In the earlier days, perhaps before C99, a local array could not be
initialized unless it was declared as a static one.

Jul 28 '06 #3
di**********@yahoo.com wrote:
hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric
One possibility is that you want the value to be remembered
during subsequent calls to the function. This applies to all kinds
of static variables not just character arrays. For another possibility
read 7.5a and 7.5b of the FAQ.

http://c-faq.com/malloc/retaggr.html

Spiros Bousbouras

Jul 28 '06 #4
lovecreatesbeauty said:
>
di**********@yahoo.com wrote:
>hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric

In the earlier days, perhaps before C99, a local array could not be
initialized unless it was declared as a static one.
Have you any evidence to support this refreshingly creative explanation?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 28 '06 #5
lovecreatesbeauty wrote:
di**********@yahoo.com wrote:
>hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric

In the earlier days, perhaps before C99, a local array could not be
initialized unless it was declared as a static one.
In C89 you could initialise a local array. I don't know about pre-ANSI
C, but that really was a long time ago.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Jul 28 '06 #6
"Ian Collins" writes:
>hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric
In what context?

The same rules apply for a character array as for any other variable.

If the array is in a compilation unit and you don't want it to be
visible elsewhere, you declare it static to avoid polluting the global
namespace with the array's name.

If the array has function scope and you wish the value to be retained
between calls, you would declare it static.
A static array will auomatically have all elements reset to 0.
Jul 28 '06 #7
osmium said:
"Ian Collins" writes:
>>hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric
In what context?

The same rules apply for a character array as for any other variable.

If the array is in a compilation unit and you don't want it to be
visible elsewhere, you declare it static to avoid polluting the global
namespace with the array's name.

If the array has function scope and you wish the value to be retained
between calls, you would declare it static.

A static array will auomatically have all elements reset to 0.
Not if it has function scope. If it's not explicitly initialised, then yes,
they will be /set/ to 0 at program start, but they will never be
automatically /reset/ to 0.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 28 '06 #8

Flash Gordon wrote:
lovecreatesbeauty wrote:
In the earlier days, perhaps before C99, a local array could not be
initialized unless it was declared as a static one.
In C89 you could initialise a local array. I don't know about pre-ANSI
C, but that really was a long time ago.
Yes, perhaps C89 already does it. In H&S5 sec4.6.4, it says that
(translated from Chinese edition) static arrays and external arrays can
be initialized in this way... Automatic arrays are allowed to be
initialized in Standard C [1], but the original C definition [2] did
not support this feature.

In Stephen Prata's C Primer Plus sec10.1.1, the author mentions the
similar thing also.

P.S. Hi Richard, why are you always in high dudgeon on c.l.c? Are you
the same in your real life? Could you clarify following doubts for me,
for I'm not an expert and do not have an English H&S5?

[1] I do not know what does "Standard C" mean in the Chinese edition of
the book, but I guess it means C89 now.
[2] pre-Ansi, K&R C or Classical C. The Chinese book does not state it
clear enough.

Jul 28 '06 #9
lovecreatesbeauty said:
>
Flash Gordon wrote:
>lovecreatesbeauty wrote:
In the earlier days, perhaps before C99, a local array could not be
initialized unless it was declared as a static one.
In C89 you could initialise a local array. I don't know about pre-ANSI
C, but that really was a long time ago.

Yes, perhaps C89 already does it.
There's no "perhaps" about it.
P.S. Hi Richard, why are you always in high dudgeon on c.l.c?
I don't suffer fools gladly.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 28 '06 #10

Richard Heathfield wrote:
lovecreatesbeauty said:
P.S. Hi Richard, why are you always in high dudgeon on c.l.c?

I don't suffer fools gladly.
Have you shown people whether you are a fool or not? Why do you have to
suffer from anything?

Jul 28 '06 #11
On Fri, 28 Jul 2006 10:00:44 +0000, Richard Heathfield
<in*****@invalid.invalidwrote:
lovecreatesbeauty said:

di**********@yahoo.com wrote:
hi...i am new to c programming....please explain me as to why should
an character array be declared as static...thanx...eric
In the earlier days, perhaps before C99, a local array could not be
initialized unless it was declared as a static one.

Have you any evidence to support this refreshingly creative explanation?
FAQ 1.31. Prestandard is indeed before C99 -- by quite a lot. <G?>
- David.Thompson1 at worldnet.att.net
Aug 14 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rahul Joshi | last post by:
Hi, I want to create a static array whose size is also a const member of the class. Something like: // A.h class A { private: static int size = 0; static int array;
1
by: John David Ratliff | last post by:
I'm new to C++ and have a question about static class constants. Let's say we have two classes --------------------------------------------- #include <iostream> using namespace std; ...
7
by: Eric | last post by:
My program will create a few instance of class A. Class A will always need this 256byte array that is used for bitcounting. I have a function that fills the array. How do a right a class or...
8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
11
by: reddy | last post by:
hi I am getting this error /tmp/ccYZ9ROC.o(.text+0x139): In function `temp::init()': : undefined reference to `temp::array' /tmp/ccYZ9ROC.o(.text+0x157): In function `temp::setArray()': :...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
12
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
3
by: Mark Dunmill | last post by:
I can't create a Constant/Read-only array field in managed C++ classes - doesn't allow the keyword const pointer to const object on array fields in managed C++ classes. e.g. Want to define a...
6
by: silverburgh.meryl | last post by:
Hi, In one A.cpp file, I have defined a static array of JSFunctionSpec, like this: static JSFunctionSpec JProfFunctions = { {"JProfStartProfiling", JProfStartProfiling, 0, 0, 0 },...
12
bilibytes
by: bilibytes | last post by:
hi, i need some help here. how can i access a static property of a subclass. i have an abstract class which will be extended... each extending class will have a static property that will...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.