473,546 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why connot declare a static member of STRUCT or UNION?

Any comments? thanks.

Jim

Oct 23 '07 #1
27 5475
ar******@gmail. com wrote:
Any comments? thanks.
Please put your question in the body of your post and don't SHOUT.

C isn't C++.

--
Ian Collins.
Oct 23 '07 #2
On Mon, 22 Oct 2007 18:14:08 -0700, ar******@gmail. com wrote in
comp.lang.c:
Any comments? thanks.
Because there is no such thing as STRUCT or UNION in C.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Oct 23 '07 #3
In article <11************ **********@k35g 2000prh.googleg roups.com>,
<ar******@gmail .comwrote:
>Any comments? thanks.
What would you expect it to mean? That, in the case of a struct,
that the rest of the struct would lose its values when the struct
went out of scope, but the static member would not? That, in
the case of a union, that... that what? That if you had last written
to it via the static member that the value would be remembered
but that it wouldn't be remembered if you had written to the
union via one of the non-static members ???
--
"History is a pile of debris" -- Laurie Anderson
Oct 23 '07 #4
ar******@gmail. com wrote:
Any comments? thanks.

Jim
In Standard C, it can't.
because C doesn't support it. C isn't a language that supports
OO programming favor.

You can use C++, and post in comp.lang.c++ .

>
-Road.
--
C FAQ: http://c-faq.com/
Oct 23 '07 #5
ar******@gmail. com wrote:
Any comments? thanks.
Note that C is case sensitive. STRUCT and UNION are not defined by the C
Standard, you probably meant struct and union.

As for your question, a struct or union is an aggregate type. That means
all it's member objects have the same scope. Though the static
qualifier can apply to the whole structure, it's application to one of
it's members makes very little sense; and I see little point in it too.

Oct 23 '07 #6
ar******@gmail. com wrote:
Any comments? thanks.
The keyword 'static' has many meanings in C, none of which make sense
inside a struct. C++ gave that keyword an additional meaning, which
applies only in that context, but this newsgroup is for discussing C,
not C++.
Oct 23 '07 #7
"James Kuyper Jr." <ja*********@ve rizon.netwrites :
ar******@gmail. com wrote:
>Any comments? thanks.

The keyword 'static' has many meanings in C, none of which make sense
inside a struct. C++ gave that keyword an additional meaning, which
applies only in that context, but this newsgroup is for discussing C,
not C++.
It would make perfect sense to see static in a struct as far as I can
see. What is so nonsensical about it? Or is your point not that it
wouldn't make sense, but that it's simply not available?
Oct 23 '07 #8
Richard wrote:
"James Kuyper Jr." <ja*********@ve rizon.netwrites :
>ar******@gmail. com wrote:
>>Any comments? thanks.
The keyword 'static' has many meanings in C, none of which make sense
inside a struct. C++ gave that keyword an additional meaning, which
applies only in that context, but this newsgroup is for discussing C,
not C++.

It would make perfect sense to see static in a struct as far as I can
see. What is so nonsensical about it? Or is your point not that it
wouldn't make sense, but that it's simply not available?
The standard defines (at least) three different meanings for the keyword
static, depending upon whether it's at file scope, block scope, or
function prototype scope. A single struct type, once defined, could be
used to declare an object in any of those scopes, so the possible
meaning of the 'static' keyword when applied to a member would have to
change with the scope.

File scope: what would it mean for a structure object to have external
linkage, but a member of that object to have internal linkage (or vice
versa)?

Block scope: What would it mean for a structure object to be
automatically or dynamically allocated, and to have a member that was
statically allocated (or vice versa)?

Function prototype scope: the only meaning currently provided for static
in this scope is that it requires that the leading dimension of an array
passed as a specific argument to the function to be at least as long as
the length specified for the corresponding parameter. I don't see how
that could be applied to struct members.

I'm not saying that answers couldn't be invented for these questions;
I'm merely saying that any answer would be a new invention, not a simple
extension to the currently defined meanings of 'static'.
Oct 23 '07 #9
James Kuyper Jr. wrote:
Richard wrote:
>It would make perfect sense to see static in a struct as far as I can
see. What is so nonsensical about it? Or is your point not that it
wouldn't make sense, but that it's simply not available?

The standard defines (at least) three different meanings for the
keyword static, depending upon whether it's at file scope, block
scope, or function prototype scope. A single struct type, once
defined, could be used to declare an object in any of those scopes, so
the possible meaning of the 'static' keyword when applied to a member
would have to change with the scope.

File scope: what would it mean for a structure object to have external
linkage, but a member of that object to have internal linkage (or vice
versa)?
Presumably that the static member is invisible to other modules?
Block scope: What would it mean for a structure object to be
automatically or dynamically allocated, and to have a member that was
statically allocated (or vice versa)?
Presumably that the static member retains it's previous value?

<snip>

Oct 23 '07 #10

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

Similar topics

3
2248
by: Doug Eleveld | last post by:
Hi Everyone, I have been playing aroung with 'object-oriented' C for a while now and I have come up with an interesting way to simulate C++ inheritance and non-member functions in C in a 100% typesafe way. The object derivation is a bit cloudy, but the code is fairly repetitive and doesn't seem to be terribly error prone. Maybe some...
1
2320
by: Michael B Allen | last post by:
Consider the following structure with a union: struct shape { int type; union { struct circle c; struct square s; struct polydoodle p; } u; };
15
5308
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have private string myArray;
11
2807
by: ziman137 | last post by:
Hi all, I have a question here. What is the rationale behind ISO C++ for Static Member Definition? * ISO C++ forbids in-class definition/initialization of non-constant static member variables. For example, instead of
5
2355
by: sharat | last post by:
hi all can any body tell how to declare the structure pointer within a class. i have written the following program but gettin error. #include<iostream> using namespace std;
3
3877
by: Hallvard B Furuseth | last post by:
to find the required alignment of a struct, I've used #include <stddef.h> struct Align_helper { char dummy; struct S align; }; enum { S_alignment = offsetof(struct Align_helper, align) };
14
28086
by: deepak | last post by:
Hi Experts, I'm getting this compilation error while trying to access a member in structure. at what time we will get this error message? Thanks, Deepak
23
252
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized to 0. ANSI C guarantees that. Technically speaking, static variables go into the .bss ELF segment, while "static int foo=0" goes into .data. ...
7
6402
by: Peter Olcott | last post by:
Why can a union have a member with a copy constructor?
0
7504
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, 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...
0
7694
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. ...
0
7947
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...
1
7461
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...
0
5080
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...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
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
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
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...

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.