<div class="gmail_quote">On 18 March 2012 03:10, Walter Bright <span dir="ltr"><<a href="mailto:newshound2@digitalmars.com">newshound2@digitalmars.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 3/17/2012 2:55 PM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I tend to think of 'struct's as 'passive', and compile-time annotations would<br>
provide me with every use case I can imagine for my own purposes in the case of<br>
structs. classes seem far more likely to need stateful attributes.<br>
</blockquote>
<br></div>
I currently find the notion of runtime attribute state to be fraught with all kinds of unresolved and murky issues with no obvious answer:<br>
<br>
1. construction/destruction<br></blockquote><div><br></div><div>After initialisation, before construction.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

2. shared<br></blockquote><div><br></div><div>How is this any different than for the class its self?</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

3. const/immutable<br></blockquote><div><br></div><div>Inherit these properties.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
4. thread locality<br></blockquote><div><br></div><div>Same as class.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
5. allocated statically or dynamically<br></blockquote><div><br></div><div>I'd say dynamically if restricted to classes, but some suggested the syntax '@attribute struct/class MyAttribute { }', which could clarify the intent.</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
6. shared library issues?<br></blockquote><div><br></div><div>If extern(D), then there should be no problems. If extern(C), then the attributes would just appear like structure members. Assuming the layout was documented (ie, in-order of appearance, at the end of the class), C/C++ could include them at the end of the class definition, and access them directly as if usual classes. All that would be lost is the implicit (compile time) association between the attribute and its associated class member.</div>
<div>I don't think it's fair to expect a novel language feature to be supported by C/C++ though.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If the attribute is code, when does that code get run?<br>
<br>
1. on initialization<br>
2. on termination<br>
3. on read<br>
4. on write<br>
5. what about read/write?<br>
</blockquote></div><br><div>I might go and read up on C# more thoroughly and get back to you... maybe others here are already more familiar with C#'s attribute management?</div><div>I'm sure C# already answers all these questions. It has precisely the same set of issues associated.</div>