hi...i am new to c programming.... please explain me as to why should
an character array be declared as static...thanx. ..eric 11 3227 di**********@ya hoo.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. di**********@ya hoo.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. di**********@ya hoo.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
lovecreatesbeau ty said:
> di**********@ya hoo.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)
lovecreatesbeau ty wrote:
di**********@ya hoo.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
"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.
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)
Flash Gordon wrote:
lovecreatesbeau ty 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.
lovecreatesbeau ty said:
>
Flash Gordon wrote:
>lovecreatesbea uty 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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
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;
class Color {
|
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 object that
will only create one of these arrays that every class A can see?
|
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: VarArray::funct were
an extern, but it is declared in the same file (q.v.). What is the
remedy for this?
=================
|
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()':
: undefined reference to `temp::array'
/tmp/ccYZ9ROC.o(.text+0x19a): In function `temp::print()':
: undefined reference to `temp::array'
collect2: ld returned 1 exit status
| |
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;
// ...
public static MyObject Object400;
|
by: Sergey Klementiev |
last post by:
Why it's impossible to have a static indexer in C#?
|
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 read/only field for an empty array
(so all the empty arrays of the given type can use the same object) however
because the pointer in the field cannot be marked as constant then it is
possible that any external party can alter this pointer to reference...
|
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
},
{"JProfStopProfiling", JProfStopProfiling,
|
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 store an array like this:
protected static $_multiLevelArray = array('one'=> array(...), 'two'=> array(...))
protected static $_finalArray;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |