Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 09, 2005 non-initialized variables | ||||
---|---|---|---|---|
| ||||
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
|
April 10, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | 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/ |
April 10, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | There's an arcane syntax for avoiding explicit initialization of stack-based arrays. As follows: # char[] x; # const int size = 2048; # # x = cast(char[]) alloca(size)[0..size]; 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 |
April 10, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | 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 |
April 10, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | 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/ |
April 10, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Nowak | 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 |
April 10, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | 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 |
April 10, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | 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/ |
April 11, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | 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 |
April 11, 2005 Re: non-initialized variables | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | 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.
|
Copyright © 1999-2021 by the D Language Foundation