473,320 Members | 1,861 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,320 software developers and data experts.

Static Var in Struct....

Can A C Program having static Variable in Structure is possible.....

i.e.

struct A
{
int a;
static int b;
};

if yes then how to access this static variable.....

As we done in C++ with A::b{i.e. using Scope Resolution}

Nov 14 '05 #1
7 11980
On 16 Mar 2005 22:03:26 -0800, "Raxit" <ra********@gmail.com> wrote in
comp.lang.c:
Can A C Program having static Variable in Structure is possible.....
No.
i.e.

struct A
{
int a;
static int b;
The members of a structure can't have storage class specifiers.
Objects of the structure type can, but they apply to all of the
members.
};

if yes then how to access this static variable.....

As we done in C++ with A::b{i.e. using Scope Resolution}


--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
I want to know...the logical Reason Why not allowing Structure has
Static Member....

Raxit

Nov 14 '05 #3
Raxit wrote:

I want to know...the logical Reason Why not allowing Structure has
Static Member....


Are you asking this again because you didn't like Jacks answer, and
is that why you didn't bother to quote anything from his answer?
Is there any connection with the strange and annoying sentence
construction you use? Surely by now you have figured out how to
use Google, if not try my sig. below.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Nov 14 '05 #4
Raxit wrote:
I want to know...the logical Reason Why not allowing Structure has
Static Member....


What counts as a logical reason?

Here's a possible reason: in C, there's little advantage to be
gained by allowing it. (Just declare a Plain Old Static Variable.)

You might say "But I want the name to hide in the struct namespace!".

I say back, "Dude, if you want namespacey things in C, there are
things you could do with *lots* more payback than static structure
members."

--
Chris "logical hedgehog" Dollin
Nov 14 '05 #5
CBFalconer wrote:
Raxit wrote:
I want to know...the logical Reason Why not allowing Structure has
Static Member....


Are you asking this again because you didn't like Jacks answer, and
is that why you didn't bother to quote anything from his answer?
Is there any connection with the strange and annoying sentence
construction you use?


He is posting from India (NNTP-Posting-Host: 202.149.200.69).
Perhaps English is not his mother tongue?

AFAICT, he's asking for a rationale.

--
Regards, Grumble
Nov 14 '05 #6
Grumble wrote:
CBFalconer wrote:
Raxit wrote:
I want to know...the logical Reason Why not allowing Structure has
Static Member....


Are you asking this again because you didn't like Jacks answer, and
is that why you didn't bother to quote anything from his answer?
Is there any connection with the strange and annoying sentence
construction you use?


He is posting from India (NNTP-Posting-Host: 202.149.200.69).
Perhaps English is not his mother tongue?

AFAICT, he's asking for a rationale.


Maybe I am made over grouchy by the foolish use of the broken
google interface, and the total lack of quotations. Especially
when it is unnecessary and I and others have been campaigning to
show how to beat it.

To answer him, a structure is a single entity, to be stored
somewhere. Static specifies the class of storage involved. It is
not feasible to store one portion one place and another elsewhere
and maintain the ability to handle it as a unit.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #7
"Raxit" <ra********@gmail.com> wrote in message
I want to know...the logical Reason Why not allowing
Structure has Static Member....


Well, if that wasn't there from the beginning, the logical
reason should rather be given the other way around:

1. Why introduce static struct member?
2. Will it break existing code?
BTW. I have no idea what "static struct member" is
in C++. :-)

--
Tor <torust AT online DOT no>

Nov 14 '05 #8

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

Similar topics

16
by: Eric | last post by:
I have a static class member variable as follows: struct A { static void Set (int i) { v = i; } static int& Get () { return v; } static int v; }; int A::v; // define A::v in the cpp file
1
by: Bryan Parkoff | last post by:
I know how to write "Pointer to Function" inside struct or class without using static, but I have decided to add static to all functions inside struct or class because I want member functions to be...
13
by: Alex Vinokur | last post by:
I have the following problem. class Base { public: void (*pfunc) (int) = 0; }; class Derived : public Base {
9
by: AnandRaj | last post by:
Hi guys, I have a few doubts in C. 1. Why static declartions are not allowed inside structs? eg struct a { static int i; }; Throws an error ..
9
by: Christian Christmann | last post by:
Hi, I have problems to initialize a static struct. Here is the meaningful part of the code: int main() { int pA = -100; struct globalMixed4 {
4
by: sandeep | last post by:
Hi why we cannot have static as a structure member? & also is there any way to achive data hiding in C at this level( i.e. access only selected structure member ) following code gives syntax...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
27
by: arkmancn | last post by:
Any comments? thanks. Jim
6
by: parag_paul | last post by:
Suppose I have a struct typedef struct atype{ int a; int b; } at; main(){ static at* j= 0;
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.