wu :: forums
« wu :: forums - No static variables in union? »

Welcome, Guest. Please Login or Register.
May 18th, 2024, 7:25am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: ThudnBlunder, Grimbal, Eigenray, william wu, towr, Icarus, SMQ)
   No static variables in union?
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: No static variables in union?  (Read 1690 times)
howard roark
Full Member
***





   


Posts: 241
No static variables in union?  
« on: Sep 25th, 2008, 9:01pm »
Quote Quote Modify Modify

Why cant we declare static variables in union?
IP Logged
GowriKumar
Junior Member
**





   
WWW Email

Gender: male
Posts: 55
Re: No static variables in union?  
« Reply #1 on: Sep 25th, 2008, 11:11pm »
Quote Quote Modify Modify

I'm little confused about the question.
 
Is the question why  this is not allowed:
union foo{
  static int il;
};
 
If yes, the following explanation might help:
static keyword applies  for  variables/functions, but not the names inside the structures/unions.
 
union foo {
  int i;
  int j;
};
 
static union foo f; /* f is of type union foo and is static */
 
 
Regards,
Gowri Kumar
« Last Edit: Sep 25th, 2008, 11:30pm by GowriKumar » IP Logged

www.gowrikumar.com
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: No static variables in union?  
« Reply #2 on: Sep 26th, 2008, 2:20am »
Quote Quote Modify Modify

A union allows you to address the same element of data in different ways. Now this would clearly pose a problem if it is at the same time static and not static.
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
RajivG
Junior Member
**





   
WWW

Gender: male
Posts: 72
Re: No static variables in union?  
« Reply #3 on: Sep 27th, 2008, 1:17am »
Quote Quote Modify Modify

now after reading it i got a problem  Roll Eyes
 
normally we do not implement grammar where i feel infeasibility of semantic and syntax implementation.
 
static variable in structure--------- > i do not see any problem, this is what c++ compiler does when we ask it to give a class with static member.. as essentially class nothing but a structure
 
now if it is question of Union and i make rule that all members should be static then complier should allow this
 
 
can some one put some light ? what problem can be there either semantic of syntactic
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board