473,656 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11994
On 16 Mar 2005 22:03:26 -0800, "Raxit" <ra********@gma il.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.l earn.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.c om, 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.c om, 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********@gma il.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
2970
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
3970
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 bound inside struct or class to become global functions. It makes easier for me to use "struct.memberfunction()" instead of "globalfunction()" when I have to use dot between struct and member function rather than global function. I do not have...
13
1673
by: Alex Vinokur | last post by:
I have the following problem. class Base { public: void (*pfunc) (int) = 0; }; class Derived : public Base {
9
2818
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
23373
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
2558
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 error struct xxxx { static int i; // int j; };
8
8921
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. Like, for instance the Objective-C method: +(void)initialize Which has the following characteristics: It is guaranteed to be run
27
5498
by: arkmancn | last post by:
Any comments? thanks. Jim
6
2110
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
8310
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 device_t { const device_backend_t *backend; ... } device_t; typedef struct device_backend_t {
0
8816
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
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 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...
1
8498
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,...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5629
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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 we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.