www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - non-initialized variables

reply "Carlos Santander B." <csantander619 gmail.com> writes:
Correct me if I'm wrong: wasn't there a syntax for stating that a 
variable shouldn't be automatically initialized? I can't remember how it 
was, and reviewing the docs I couldn't find anything.

-- 
Carlos Santander Bernal

JP2, you'll always live in our minds
Apr 09 2005
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Carlos Santander B. wrote:
 Correct me if I'm wrong: wasn't there a syntax for stating that a 
 variable shouldn't be automatically initialized? I can't remember how it 
 was, and reviewing the docs I couldn't find anything.
Many posters have proposed a syntax when requesting such a feature be added to D, but Walter hasn't accepted any of the proposals. -- jcc7 http://jcc_7.tripod.com/d/
Apr 09 2005
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
J C Calvarese <jcc7 cox.net> wrote:

 but Walter hasn't accepted any of the proposals. 
You forget http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15598 Walter seems convinced from the "= void" syntax. -manfred
Apr 09 2005
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Manfred Nowak wrote:
 J C Calvarese <jcc7 cox.net> wrote:
 
 
but Walter hasn't accepted any of the proposals. 
You forget http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15598 Walter seems convinced from the "= void" syntax. -manfred
You're absolutely correct. I did forget about that. I don't think he's implemented it yet, but maybe it will happen sometime sooner rather than later. Maybe someone should remind Walter. ;) (I don't know that I'd ever use such a feature, but it seems like a reasonable request to make it easy for programmers who desire that power.) -- jcc7 http://jcc_7.tripod.com/d/
Apr 09 2005
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
J C Calvarese wrote:

 http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15598

 Walter seems convinced from the "= void" syntax.
You're absolutely correct. I did forget about that. I don't think he's implemented it yet, but maybe it will happen sometime sooner rather than later. Maybe someone should remind Walter. ;) (I don't know that I'd ever use such a feature, but it seems like a reasonable request to make it easy for programmers who desire that power.)
While we're speaking of improving the values of initialized variables, even better would be to switch characters and floating points from the current "as-awkward-default-value-as-possible" .init, and have them also start using zeroes like everything else... That would (by accident) also fix the broken starting values of arrays and automagic hash values, too. (that are supposed to have .init values, but just have zeroes right now) But "= void" sounds like a resonable syntax for "make mine C, please". (or "I prefer my variables having random values, thank you very much") Would come in handy in some specialized optimization cases, I guess... --anders
Apr 10 2005
parent Manfred Nowak <svv1999 hotmail.com> writes:
Anders F Björklund <afb algonet.se> wrote:

 even better would be to switch characters and
 floating points from the current
 "as-awkward-default-value-as-possible" .init, and have them also 
 start using zeroes like everything else...
I think, that the idea to have a mechanism for preventing non deterministic behaviour is a good one. But the implementation of such a mechanism by preinitializing the space used by the variables to some pattern is too unclean as the on and on going remarks on this topic show. There is a solution in additional linear time and space which I have outlined in http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/19936 This seems acceptable for at least debug builds, because before reaching the release stage time and space considerations should be less important. -manfred
Apr 11 2005
prev sibling parent reply "Carlos Santander B." <csantander619 gmail.com> writes:
Manfred Nowak wrote:
 J C Calvarese <jcc7 cox.net> wrote:
 
 
but Walter hasn't accepted any of the proposals. 
You forget http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15598 Walter seems convinced from the "= void" syntax. -manfred
That's what I had in mind. I thought it had been implemented. -- Carlos Santander Bernal JP2, you'll always live in our minds
Apr 10 2005
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Carlos Santander B. wrote:
 Manfred Nowak wrote:
 
 J C Calvarese <jcc7 cox.net> wrote:


 but Walter hasn't accepted any of the proposals. 
You forget http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15598 Walter seems convinced from the "= void" syntax. -manfred
That's what I had in mind. I thought it had been implemented.
"I've been considering implementing it" is a bit different than "I like it and it's now part of D". I just searched through the changelog and I couldn't find any indication that it had been added. If I weren't so lazy, I'd type up a short "= void" example and see if it compiles. ;) -- jcc7 http://jcc_7.tripod.com/d/
Apr 10 2005
parent reply Georg Wrede <georg.wrede nospam.org> writes:
J C Calvarese wrote:
 Carlos Santander B. wrote:
 
 Manfred Nowak wrote:

 J C Calvarese <jcc7 cox.net> wrote:


 but Walter hasn't accepted any of the proposals. 
You forget http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15598 Walter seems convinced from the "= void" syntax. -manfred
That's what I had in mind. I thought it had been implemented.
"I've been considering implementing it" is a bit different than "I like it and it's now part of D". I just searched through the changelog and I couldn't find any indication that it had been added. If I weren't so lazy, I'd type up a short "= void" example and see if it compiles. ;)
I fail to see the utility of this. Consider this: if someone is making code that has to be optimized to such an extent that the time to zero out a variable (which really does not take very much time), becomes significant, then one probably would resort to reusing variables anyhow. Right? Especially so, with a GC language. Also, the D optimizer skips the zeroing anyhow when it sees that the variable is assigned to before use. So the only reason left for not initialising is to spy on memory. And that can already be done in D. Except that Real Operating systems prevent you from acquiring virgin memory without it getting zeroed out, so you still can't spy on others.
Apr 11 2005
parent Manfred Nowak <svv1999 hotmail.com> writes:
Georg Wrede <georg.wrede nospam.org> wrote:

[...]
 time to zero out a variable (which really does not take very
 much time) 
Memory currently widely used is PC3200 which means that 3.2GB/s can be _read_. The write performance is at about 1.1GB/s according to aida32. This means that timeslicing at 200Hz and above limits the size of memory chunks that can be written to within one timeslice to 5.5MB or less. So that is the space bound to variables we are talking of.
 Also, the D optimizer skips the zeroing anyhow when it sees that
 the variable is assigned to before use.
Better use "if" instead of "when", because in general the compiler cannot see whether a variable is assigned to before use.
 So the only reason left for not initialising is to spy on
 memory. 
[...] As pointed out above at least arrays occupying more than 5MB are of interest. -manfred
Apr 11 2005
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"Carlos Santander B." <csantander619 gmail.com> wrote in message
news:d3bc8f$2cjb$3 digitaldaemon.com...
 Manfred Nowak wrote:
 http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/15598
 Walter seems convinced from the "= void" syntax.
That's what I had in mind. I thought it had been implemented.
No, not yet.
Apr 15 2005
prev sibling parent "Kris" <fu bar.com> writes:
There's an arcane syntax for avoiding explicit initialization of stack-based
arrays. As follows:






It avoids initialization only when one uses a constant for the size. Perhaps
that could use some syntactic sugar?

- Kris


"Carlos Santander B." <csantander619 gmail.com> wrote in message
news:d39ojr$2ts8$1 digitaldaemon.com...
 Correct me if I'm wrong: wasn't there a syntax for stating that a
 variable shouldn't be automatically initialized? I can't remember how it
 was, and reviewing the docs I couldn't find anything.

 -- 
 Carlos Santander Bernal

 JP2, you'll always live in our minds
Apr 09 2005