www.digitalmars.com         C & C++   DMDScript  

D - [dmd crash] on global scope operator

reply Manfred Nowak <svv1999 hotmail.com> writes:
dmd 0.81 on WIN98SE crashes on:

const char[1] arr;
char[] arr2=.arr[];

So long.
Mar 12 2004
parent reply Andrew Edwards <remove_ridimz remove_yahoo.com> writes:
On Sat, 13 Mar 2004 07:42:05 +0100, Manfred Nowak <svv1999 hotmail.com> 
wrote:

 dmd 0.81 on WIN98SE crashes on:

 const char[1] arr;
 char[] arr2=.arr[];

 So long.
Not sure what the . in .arr[] represents but your code compiles correctly without it. Andrew
Mar 13 2004
next sibling parent J C Calvarese <jcc7 cox.net> writes:
Andrew Edwards wrote:
 On Sat, 13 Mar 2004 07:42:05 +0100, Manfred Nowak <svv1999 hotmail.com> 
 wrote:
 
 dmd 0.81 on WIN98SE crashes on:

 const char[1] arr;
 char[] arr2=.arr[];

 So long.
Not sure what the . in .arr[] represents but your code compiles correctly without it.
I think it's supposed to be a Module Scope Operator (see http://www.digitalmars.com/d/module.html). It looks like valid code to me, but whether it's valid or not, DMD shouldn't GPF when it's compiled. So I'd call it a bug.
 
 Andrew
-- Justin http://jcc_7.tripod.com/d/
Mar 13 2004
prev sibling parent reply Manfred Nowak <svv1999 hotmail.com> writes:
Andrew Edwards wrote:

[...]
 your code compiles correctly without it.
I know that. As always when reducing something to the minimum, the stimulating context is lost. I deleted three unnecessary lines from that test where it made more sense: const char[1] arr; void main(){ const char[2] arr; char[] arr2=.arr[]; } So long.
Mar 13 2004
parent reply Andrew Edwards <remove_ridimz remove_yahoo.com> writes:
On Sun, 14 Mar 2004 00:47:36 +0100, Manfred Nowak <svv1999 hotmail.com> 
wrote:

 Andrew Edwards wrote:

 [...]
 your code compiles correctly without it.
I know that. As always when reducing something to the minimum, the stimulating context is lost. I deleted three unnecessary lines from that test where it made more sense: const char[1] arr; void main(){ const char[2] arr; char[] arr2=.arr[]; } So long.
Your intentions is much clearer. As for the GPF generated by your code, well, its a bug that needs to be addressed. However, why would you declare a costant and not initialize it. The very nature of constant variables suggests and often dictates that they must be initialized upon declaration (defined vs declared). That being the case, const char[1] arr = '1'; // defined: not just declared void main(){ const char[2] arr; char[] arr2=.arr[]; } yields a more desireable result. Of course the compiler should identify the source of the problem instead of simply GPFing. Andrew -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Mar 14 2004
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
Andrew Edwards wrote:

[...]
 often dictates that they must be initialized
[...] Remember that D has automatic initialization. Therefore the crashes here are due to the gobal/module scope operator. This does not crash: const char[1] arr; void main(){ char[] arr2=arr[]; printf("'%c'\n", arr[0]); } but with global/module scope operator it crashes: const char[1] arr; void main(){ char[] arr2=arr[]; printf("'%c'\n", .arr[0]); } This does not crash const char[1] arr; void main(){ const char[1] arr; char[] arr2=arr[]; printf("'%c'\n", arr[0]); } but with global/module scope operator it crashes: const char[1] arr; void main(){ const char[1] arr; char[] arr2=arr[]; printf("'%c'\n", .arr[0]); } So long!
Mar 14 2004
parent reply Andrew Edwards <remove_ridimz remove_yahoo.com> writes:
On Sun, 14 Mar 2004 17:19:04 +0100, Manfred Nowak <svv1999 hotmail.com> 
wrote:

 Andrew Edwards wrote:

 [...]
 often dictates that they must be initialized
[...] Remember that D has automatic initialization. Therefore the crashes here are due to the gobal/module scope operator.
I see your point. But this is one case, IMHO, where automatic initialization should not be allowed. A constant is just that "constant". The compiler cannot possibly assume what the author intended for it to represent. If you are going to use a constant, then I'd think it must be explicitly initialized, otherwise you should use a regular variable. This works fine: char[1] arr; // not a constant void main() { const char[2] arr; char[] arr2 = .arr[]; printf(arr2); } And so does this: const char[1] arr = '1'; // initialized constant void main() { const char[2] arr; char[] arr2 = .arr[]; printf(arr2); } So while I don't dispute that the global/module scope operator contributes to the problem, I do know that the problem is compounded by the fact that it is constant. Additionally, because constants are intended to represent non-changing values, they should be explicitly initialized at declaration. Given you initial program: const char[1] arr; void main() { const char[2] arr; char[] arr2 = .arr[]; printf(arr2); } The compiler should respond as follows: crash.d(1): uninitialized constant crash.d(4): uninitialized constant problem solved. Andrew -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Mar 14 2004
parent Manfred Nowak <svv1999 hotmail.com> writes:
Andrew Edwards wrote:

[...]
 The compiler should respond as follows:
 
 crash.d(1): uninitialized constant
 crash.d(4): uninitialized constant
 
 problem solved.
Agreed. It is probably very seldom, that there is the wish to initialize a constant to the default initilizer for variables. In this rare cases the constant should be initialized explicitely. So long!
Mar 15 2004