|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D - Const spec status.
This post is *not* another const proposal. I want to know if something changed with the const system. You see: Somewhere during the const discussions, I fired up Eclipse (shameless publicity) and started testing various code samples around const/invariant. This was around const version 3, however, most of the code samples I tried didn't work as I expected. It wasn't that I didn't grok const, it just seemed the spec had changed somewhat. (and it wasn't bug fixes either, as I was following those around, at least the publicly know ones, so I would recognized them) It was if we were now in a version 4 of const (I say version 4 because this "new" version seem much better than 3). But I checked the spec: http://www.digitalmars.com/d/2.0/const3.html and nothing had changed. Everything seemed to be according to the spec. So now I got confused. Maybe Walter's comments in the NG put me offtrack? To test this theory, *and has an interesting exercise on itself*, I ask any participant in the NG who thinks they have a fair understanding of const, to consider these simple 6 cases of const usage: ---- ---- module test; import std.stdio; struct Struct { int x; } void main() { // helper objects int num = 10; invariant(int) inv_num = 1; invariant(int[]) inv_intArray = [1, 2]; invariant(Object) inv_object = cast(invariant) new Object(); invariant Struct inv_Struct = { 1 }; /** 6 Const cases **/ // Case 1 int a = inv_num; // Case 2 invariant(int) b = num; // Case 3 const(int)[] c = inv_intArray; // Case 4 int[] d = inv_intArray; // Case 5 Object e = inv_object; // Case 6 Struct f = inv_Struct; } ---- ---- and tell which ones you think are valid and which are not. Before running them through the compiler of course! (or checking other's answers) Just look at the current documentation (http://www.digitalmars.com/d/2.0/const3.html), and/or what has been said in the newsgroups, to try to figure it out. Also, nothing of this has changed with 2.013, it worked the same with at least 2.012. I think we may see some interesting results. Also, with the answers to code cases above, one can quickly construct a case that (yet again) actually *breaks* the const system. -- Bruno Medeiros - Software Developer, MSc. in CS/E graduate http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D Apr 27 2008
On 27/04/2008, Bruno Medeiros <brunodomedeiros+spam com.gmail> wrote:and tell which ones you think are valid and which are not. Before running Apr 27 2008
Janice Caron wrote:On 27/04/2008, Bruno Medeiros <brunodomedeiros+spam com.gmail> wrote:and tell which ones you think are valid and which are not. Before running Apr 28 2008
Janice Caron wrote:2008/4/29 Bruno Medeiros <brunodomedeiros+spam com.gmail>:Hum, I feel a bit silly, I originally thought that *all* cases would be an error, so maybe it was just I that got confused with a previous version of const. (where values could only be assigned to variables with the same "head-constness", which is not the case here) Apr 29 2008
Bruno Medeiros <brunodomedeiros+spam com.gmail> wrote: Apr 27 2008
Simen Kjaeraas wrote: Apr 28 2008
Bruno Medeiros wrote:Somewhere during the const discussions, I fired up Eclipse (shameless publicity) Apr 28 2008
Robert Fraser wrote:Bruno Medeiros wrote:Somewhere during the const discussions, I fired up Eclipse (shameless publicity) Apr 28 2008
2008/4/29 Bruno Medeiros <brunodomedeiros+spam com.gmail>:Hum, I feel a bit silly, I originally thought that *all* cases would be an error, so maybe it was just I that got confused with a previous version of const. (where values could only be assigned to variables with the same "head-constness", which is not the case here) Apr 28 2008
|