www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Ana Kedi

reply Salih Dincer <salihdb hotmail.com> writes:
Hi, what do you think should have been in lieu of runtime error?

Thanks,

```d

/* No compile error for v2 & v3
  *
  * Runtime Error:
  *   Segmentation fault (core dumped)
  *
  * Compiler:
  *   rdmd playground.d
  */

struct Ana
{
   char a;
   // Kedi k;  //  assertions complated
   
   union
   {
     char b;
     char p;
   }

   union Kedi
   {
     char cat;
     char edi;
   }

}

      Ana ana = {
         97,
         k : Ana.Kedi(107),
         98
      };

   // ana.writeln(", ", ana.k.edi);


with(ana)
{
     assert(b == 'b'); // 'b' == 98
     assert(b == p);   // p == 'b'

     assert(k.cat == 'k');   // 'k' == 107
     assert(k.cat == k.edi); // k.edi == 'k'
}
```

SDB 79
Aug 12 2022
next sibling parent frame <frame86 live.com> writes:
On Friday, 12 August 2022 at 23:04:50 UTC, Salih Dincer wrote:
 Hi, what do you think should have been in lieu of runtime error?
DMD on Windows, LDC refuses to compile with "too many initializers for `Ana`", both are good with explicit member initializers.
Aug 13 2022
prev sibling parent reply Ivan Kazmenko <gassa mail.ru> writes:
On Friday, 12 August 2022 at 23:04:50 UTC, Salih Dincer wrote:
 Hi, what do you think should have been in lieu of runtime error?
 ...
Related: there is a version statement, resembling `{$ifdef}` in Pascal or `#ifdef` in C, but arguably cleaner. Consider this: ``` struct Ana { char a; version (v1) {Kedi k;} // assertions complated union { char b; char p; } union Kedi { char cat; char edi; } } ``` Then compile with `dmd -version v3` or the like. Note that the `{}` for compile-time features (such as `version`, `debug` or `static if`) don't introduce a new scope. Ivan Kazmenko.
Aug 15 2022
parent reply bauss <jacobbauss gmail.com> writes:
On Monday, 15 August 2022 at 16:34:29 UTC, Ivan Kazmenko wrote:
 On Friday, 12 August 2022 at 23:04:50 UTC, Salih Dincer wrote:
 Hi, what do you think should have been in lieu of runtime 
 error?
 ...
Related: there is a version statement, resembling `{$ifdef}` in Pascal or `#ifdef` in C, but arguably cleaner. Consider this: ``` struct Ana { char a; version (v1) {Kedi k;} // assertions complated union { char b; char p; } union Kedi { char cat; char edi; } } ``` Then compile with `dmd -version v3` or the like. Note that the `{}` for compile-time features (such as `version`, `debug` or `static if`) don't introduce a new scope. Ivan Kazmenko.
debug creates a new scope.
Aug 15 2022
next sibling parent Ivan Kazmenko <gassa mail.ru> writes:
On Tuesday, 16 August 2022 at 06:16:23 UTC, bauss wrote:
 On Monday, 15 August 2022 at 16:34:29 UTC, Ivan Kazmenko wrote:
 Note that the `{}` for compile-time features (such as 
 `version`, `debug` or `static if`) don't introduce a new scope.

 Ivan Kazmenko.
debug creates a new scope.
Hmm, on the contrary, this works for me (dmd 2.0.100): ``` debug {int i;} else {long i;} pragma (msg, typeof (i)); void main () {i = 2;} ``` Ivan Kazmenko.
Aug 16 2022
prev sibling parent Adam D Ruppe <destructionator gmail.com> writes:
On Tuesday, 16 August 2022 at 06:16:23 UTC, bauss wrote:
 debug creates a new scope.
debug and version work exactly the same way. there's no new scope.
Aug 16 2022