Author |
Topic: No static variables in union? (Read 1711 times) |
|
howard roark
Full Member
Posts: 241
|
|
No static variables in union?
« on: Sep 25th, 2008, 9:01pm » |
Quote Modify
|
Why cant we declare static variables in union?
|
|
IP Logged |
|
|
|
GowriKumar
Junior Member
Gender:
Posts: 55
|
|
Re: No static variables in union?
« Reply #1 on: Sep 25th, 2008, 11:11pm » |
Quote 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:
Posts: 13730
|
|
Re: No static variables in union?
« Reply #2 on: Sep 26th, 2008, 2:20am » |
Quote 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
Gender:
Posts: 72
|
|
Re: No static variables in union?
« Reply #3 on: Sep 27th, 2008, 1:17am » |
Quote Modify
|
now after reading it i got a problem 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 |
|
|
|
|