Thread overview
Ana Kedi
Aug 12, 2022
Salih Dincer
Aug 14, 2022
frame
Aug 15, 2022
Ivan Kazmenko
Aug 16, 2022
bauss
Aug 16, 2022
Ivan Kazmenko
Aug 16, 2022
Adam D Ruppe
August 12, 2022

Hi, what do you think should have been in lieu of runtime error?

Thanks,


/* 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;
  }
  //Kedi k;  //  #.v2 (compiled it)
  union Kedi
  {
    char cat;
    char edi;
  }
  //Kedi k;  //  #.v3 (compiled it)
}

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

  // ana.writeln(", ", ana.k.edi);
  // Ana('a', Kedi, #{overlap b, p}), k

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

August 14, 2022
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?

This seems to address some bugs? Except #1, it happily crashes DMD on Windows, LDC refuses to compile with "too many initializers for `Ana`", both are good with explicit member initializers.
August 15, 2022

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;
  }
  version (v2) {Kedi k;}  //  #.v2 (compiled it)
  union Kedi
  {
    char cat;
    char edi;
  }
  version (v3) {Kedi k;}  //  #.v3 (compiled it)
}

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.

August 16, 2022

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;
  }
  version (v2) {Kedi k;}  //  #.v2 (compiled it)
  union Kedi
  {
    char cat;
    char edi;
  }
  version (v3) {Kedi k;}  //  #.v3 (compiled it)
}

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.

August 16, 2022

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.

August 16, 2022
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.