473,406 Members | 2,336 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,406 software developers and data experts.

?? Definite Assignment of Structs -- Language Spec Issue ??

Hi All,

I was hoping someone could clarify something I read in the C# Language Spec
regarding "Definite Assignment" of structs. This is a very subtle point.

I am referring to ECMA-334, section 12.3:

The definite assignment states of instance variable of a struct-type
variable are tracked individually as well as collectively. In addition to
the rules above, the following rules apply to struct-type variables and
their instance variables:

* An instance variable is considered definitely assigned if its
containing struct-type variable is considered definitely assigned.
* A struct-type variable is considered definitely assigned if each of
its instance variable is considered definitely assigned.
It seems like the two bullet points above can result in circular logic
depending on one's interpretation. If you interpret these points as:

* An instance variable is considered definitely assigned if and only if
its containing struct-type variable is considered definitely assigned.
* A struct-type variable is considered definitely assigned if and only
if each of its instance variable is considered definitely assigned.

then we have a deadlock situation because a struct's instance members are
definitely assigned exactly when the struct variable is definitely assigned.
But the struct variable is definitely assigned exactly when all its instance
variables are definitely assigned. It's the Chicken and the Egg Problem.

Now, I realize the meaning of "if" is much different from that of "if and
only if" but I'm wondering about the intent of the passages. Did the authors
really mean "if and only if"? I doubt it. I suspect the authors meant "if",
as it's written.

(I told you it was subtle). So, if the authors of the spec meant "if", as it
was written, then there must be some way for the instance variables of a
struct variable to be definitely assigned other than the struct variable
itself being definitely assigned. Similarly, there must be some way for the
struct variable to be definitely assigned other than having all its instance
variables definitely assigned.

So (whew!), assuming the authors of the spec meant to say "if" and not "if
and only if", my question is, how can the instance variables of a struct be
definitely assigned without the containing struct variable being definitely
assigned? And, how can a struct instance variable be definitely assigned
without all of its instance variables being definitely assigned?

If you tell me there is a mutual dependency between the struct instance
members and the struct variable itself, then you are telling me we have a
Chicken and Egg Problem.

Anyone still reading??? Thanks!
--
Tom Baxter

Oct 30 '07 #1
1 1278
On 2007-10-29 20:57:12 -0700, "Tom Baxter" <tl********@newsgroup.nospamsaid:
[...] So (whew!), assuming the authors of the spec meant to say "if"
and not "if and only if", my question is, how can the instance
variables of a struct be definitely assigned without the containing
struct variable being definitely assigned?
Simple:

struct A
{
public int x;
public int y;
}

void Method()
{
A a; // a, a.x, and a.y are not definitely assigned

a.x = 1; // a.x is definitely assigned, a, a.y are not
a.y = 2; // a.y is definitely assigned, as is a
}
And, how can a struct instance variable be definitely assigned without
all of its instance variables being definitely assigned?
It can't. Thus the first clause. If the struct itself is definitely
assigned, then all of the instance variables are definitely assigned as
well.

Pete

Oct 30 '07 #2

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

Similar topics

23
by: Paul Rubin | last post by:
OK, I want to scan a file for lines matching a certain regexp. I'd like to use an assignment expression, like for line in file: if (g := re.match(pat, line)): croggle(g.group(1)) Since...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
6
by: Neil Zanella | last post by:
Hello, I would like to know whether the following C fragment is legal in standard C and behaves as intended under conforming implementations... union foo { char c; double d; };
19
by: Jasper Kent | last post by:
Can anyone explain the logic behind structs being allowed neither memeber initialisers or default constructors. Doesn't this just encourage developers to create constructors with dummy...
4
by: sadhu | last post by:
Hi All, I was surprised to see the readonly behavior differ with respect to properties and methods. struct Foo { int state; public int State
16
by: Michi Henning | last post by:
Below is a bit of code that creates a delegate. The delegate invokes a member function of a struct. The code compiles, but has surprising behavior: using System; namespace ConsoleApplication1...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
2
by: muler | last post by:
Hi all, This is an excerpt from the Book "Programming Microsoft Visual C#: The Language": A function evaluates to the return value. When a reference type is returned, a function is available...
13
by: Tom Baxter | last post by:
Hi everyone, Has anyone looked at section 18.1.1 of the C# spec? It indicates 'new' and 'protected' are valid modifiers on struct declarations. First, how can 'protected' be valid on a struct,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.