Re: Union Initialization

2018-01-30 Thread Ali Çehreli via Digitalmars-d-learn

On 01/30/2018 07:33 PM, Rubn wrote:


Is there any way to initialize an array of unions with more than just 
the first union type?



struct A { float a; }
struct B { uint b; }

union Test
{
     A a;
     B b;
}

Test[2] test =
[
     Test(A(1.0f)),
     Test(B(10)), // ERROR
];


AFAIK there's no way to specify to use D with an initializer:

Test test = { b: B(10) };


You can have explicit constructors:


union Test
{
A a;
B b;

this(A a) {
this.a = a;
}

this(B b) {
this.b = b;
}
}

Ali


Union Initialization

2018-01-30 Thread Rubn via Digitalmars-d-learn


Is there any way to initialize an array of unions with more than 
just the first union type?



struct A { float a; }
struct B { uint b; }

union Test
{
A a;
B b;
}

Test[2] test =
[
Test(A(1.0f)),
Test(B(10)), // ERROR
];


AFAIK there's no way to specify to use D with an initializer:

Test test = { b: B(10) };


Re: D1: Error: duplicate union initialization for size

2014-09-02 Thread jicman via Digitalmars-d-learn

On Monday, 1 September 2014 at 15:44:50 UTC, Dicebot wrote:

On Sunday, 31 August 2014 at 03:06:48 UTC, Dicebot wrote:
My guess is that it hasn't been ported to the D1 compiler 
yet. Dicebot or any other people who work for Sociomantic 
should be most helpful. At this point, I recommend that you 
ask on the main D forum.


Ali


I have not encountered such issue in our D1 codebase but I 
will forward this question to our internal chat on Monday


Have asked, no immediate recognition, sorry.


What does the error mean?



Re: D1: Error: duplicate union initialization for size

2014-09-01 Thread Dicebot via Digitalmars-d-learn

On Sunday, 31 August 2014 at 03:06:48 UTC, Dicebot wrote:
My guess is that it hasn't been ported to the D1 compiler yet. 
Dicebot or any other people who work for Sociomantic should be 
most helpful. At this point, I recommend that you ask on the 
main D forum.


Ali


I have not encountered such issue in our D1 codebase but I will 
forward this question to our internal chat on Monday


Have asked, no immediate recognition, sorry.


Re: D1: Error: duplicate union initialization for size

2014-08-31 Thread Jacob Carlborg via Digitalmars-d-learn

On 2014-08-31 04:53, Ali Çehreli wrote:

On 08/30/2014 06:05 PM, jicman wrote:

 > Really is or how one can fix it?  This is the only time that I have
 > found myself without answers with D.  Strange.  Maybe folks are not that
 > into D1, but D1 was before D2.  Any thoughts would be greatly
 > appreciated.  Even from Walter. :-)  Thanks.

I still think this is the same bug that I have linked before:

   https://issues.dlang.org/show_bug.cgi?id=8902

My guess is that it hasn't been ported to the D1 compiler yet. Dicebot
or any other people who work for Sociomantic should be most helpful. At
this point, I recommend that you ask on the main D forum.


That might be the case but this code doesn't involve a union. "Size" is 
a struct.


The fix for the issue above requires minimal changes [1]. Perhaps it's 
worth a try to port to D1.


[1] 
https://github.com/D-Programming-Language/dmd/commit/840d88a6e539e9817cffdc4abe8ad6357897d54a


--
/Jacob Carlborg


Re: D1: Error: duplicate union initialization for size

2014-08-30 Thread Dicebot via Digitalmars-d-learn

On Sunday, 31 August 2014 at 02:53:35 UTC, Ali Çehreli wrote:

On 08/30/2014 06:05 PM, jicman wrote:

> Really is or how one can fix it?  This is the only time that
I have
> found myself without answers with D.  Strange.  Maybe folks
are not that
> into D1, but D1 was before D2.  Any thoughts would be greatly
> appreciated.  Even from Walter. :-)  Thanks.

I still think this is the same bug that I have linked before:

  https://issues.dlang.org/show_bug.cgi?id=8902

My guess is that it hasn't been ported to the D1 compiler yet. 
Dicebot or any other people who work for Sociomantic should be 
most helpful. At this point, I recommend that you ask on the 
main D forum.


Ali


I have not encountered such issue in our D1 codebase but I will 
forward this question to our internal chat on Monday


Re: D1: Error: duplicate union initialization for size

2014-08-30 Thread Ali Çehreli via Digitalmars-d-learn

On 08/30/2014 06:05 PM, jicman wrote:

> Really is or how one can fix it?  This is the only time that I have
> found myself without answers with D.  Strange.  Maybe folks are not that
> into D1, but D1 was before D2.  Any thoughts would be greatly
> appreciated.  Even from Walter. :-)  Thanks.

I still think this is the same bug that I have linked before:

  https://issues.dlang.org/show_bug.cgi?id=8902

My guess is that it hasn't been ported to the D1 compiler yet. Dicebot 
or any other people who work for Sociomantic should be most helpful. At 
this point, I recommend that you ask on the main D forum.


Ali



Re: D1: Error: duplicate union initialization for size

2014-08-30 Thread jicman via Digitalmars-d-learn

On Thursday, 28 August 2014 at 06:17:13 UTC, Jacob Carlborg wrote:

On 27/08/14 23:48, jicman wrote:

On Wednesday, 27 August 2014 at 06:20:24 UTC, Jacob Carlborg
wrote:

On 23/08/14 19:50, jicman wrote:


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.


Does the following make any difference?

const Size DEFAULT_SCAL = Size(5, 13)


I changed it from this,

const Size DEFAULT_SCALE = { 5, 13 };

to this,

const Size DEFAULT_SCALE = Size(5,13);

and now I am getting 4 errors: :-)


Of course you do :) I have honestly no idea what's going on.


So, I guess no one in this forum knows what the D1 error,

D1: Error: duplicate union initialization for size

Really is or how one can fix it?  This is the only time that I 
have found myself without answers with D.  Strange.  Maybe folks 
are not that into D1, but D1 was before D2.  Any thoughts would 
be greatly appreciated.  Even from Walter. :-)  Thanks.


josé



Re: D1: Error: duplicate union initialization for size

2014-08-27 Thread Jacob Carlborg via Digitalmars-d-learn

On 27/08/14 23:48, jicman wrote:

On Wednesday, 27 August 2014 at 06:20:24 UTC, Jacob Carlborg
wrote:

On 23/08/14 19:50, jicman wrote:


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.


Does the following make any difference?

const Size DEFAULT_SCAL = Size(5, 13)


I changed it from this,

const Size DEFAULT_SCALE = { 5, 13 };

to this,

const Size DEFAULT_SCALE = Size(5,13);

and now I am getting 4 errors: :-)


Of course you do :) I have honestly no idea what's going on.

--
/Jacob Carlborg


Re: D1: Error: duplicate union initialization for size

2014-08-27 Thread jicman via Digitalmars-d-learn

On Wednesday, 27 August 2014 at 06:20:24 UTC, Jacob Carlborg
wrote:

On 23/08/14 19:50, jicman wrote:


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.


Does the following make any difference?

const Size DEFAULT_SCAL = Size(5, 13)


I changed it from this,

const Size DEFAULT_SCALE = { 5, 13 };

to this,

const Size DEFAULT_SCALE = Size(5,13);

and now I am getting 4 errors: :-)

build -I..;c:\D\import -version=gui -version=Phobos -g
OpenProjs.res  OpenProjs.d
c:\D\import\dfl\control.d(7635): Error: duplicate union
initialization for size
c:\D\import\dfl\control.d(7954): Error: duplicate union
initialization for size
c:\D\import\dfl\control.d(7954): Error: duplicate union
initialization for size
c:\D\import\dfl\control.d(7954): Error: duplicate union
initialization for size

Line 7635:
const Size DEFAULT_SCALE = Size(5,13);

Line 7954:
Size autossz = DEFAULT_SCALE;

But, look at line 7955:

Size scrollsz = { 0, 0 };

And there is no error for that line.  Changing the 5 and 13 for
0, 0, has now taken that error out, but what does that mean?
What if I needed that 5 and 13 there?



Re: D1: Error: duplicate union initialization for size

2014-08-26 Thread Jacob Carlborg via Digitalmars-d-learn

On 27/08/14 04:38, jicman wrote:


I wish I knew. :-(  Above, in this same post I pasted all lines that had
Size and right below it all lines that had size.  These are all the
places where Size is found.  If you can tell me which one you think it
is, I can grab that piece of the code.


I found it, I think. It's declared in "drawing.d". Well, at least I 
found one declared there. But that's not a union, it's a struct. I don't 
understand why it complains about a struct.


--
/Jacob Carlborg


Re: D1: Error: duplicate union initialization for size

2014-08-26 Thread Jacob Carlborg via Digitalmars-d-learn

On 23/08/14 19:50, jicman wrote:


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.


Does the following make any difference?

const Size DEFAULT_SCAL = Size(5, 13)

--
/Jacob Carlborg


Re: D1: Error: duplicate union initialization for size

2014-08-26 Thread jicman via Digitalmars-d-learn


On Tuesday, 26 August 2014 at 06:36:59 UTC, Jacob Carlborg wrote:

On 26/08/14 00:57, jicman wrote:


Ok, let's try something simpler...  Where can I find the D1 
v1.076

compiler error meaning of,

Error: duplicate union initialization for size

for this line,

const Size DEFAULT_SCALE = { 5, 13 };


How does the code for Size look like?


I wish I knew. :-(  Above, in this same post I pasted all lines 
that had Size and right below it all lines that had size.  These 
are all the places where Size is found.  If you can tell me which 
one you think it is, I can grab that piece of the code.


Tehse are all the lines where Size is found in all the dfl
library files:

clientSize = Size(340, 150);
final Size size() // getter
Size result;
Size defaultSize() // getter
return Size(75, 23);
override Size defaultSize() // getter
return Size(120, 23); // ?
final Size clientSize() // getter
final void clientSize(Size sz) // setter
//wclientsz = Size(width, height);
final void size(Size sz) // setter
final Size size() // getter
return wrect.size; // struct Size, not sizeof.
final Size getAutoScaleSize(Font f)
Size result;
final Size getAutoScaleSize()
package final Size _fetchClientSize()
return Size(r.right, r.bottom);
Size defaultSize() // getter
return Size(0, 0);
Size wclientsz;
deprecated final void autoScrollMargin(Size sz) // setter
deprecated final Size autoScrollMargin() // getter
return Size(0, 0);
deprecated final void autoScrollMinSize(Size sz) // setter
deprecated final Size autoScrollMinSize() // getter
return Size(0, 0);
final Size autoScaleBaseSize() // getter
final void autoScaleBaseSize(Size newSize) // setter
static Size calcScale(Size area, Size toScale, Size fromScale)
// package
Size calcScale(Size area, Size toScale) // package
final void _scale(Size toScale) // package
void xscale(Control c, Size fromScale)
Size sz;
sz = calcScale(Size(c.left, c.top), toScale, 
fromScale);
final void scrollSize(Size sz) // setter
final Size scrollSize() // getter
const Size DEFAULT_SCALE = { 5, 13 };
//Size scrollmargin, scrollmin;
Size autossz = DEFAULT_SCALE;
Size scrollsz = { 0, 0 };
Point opAdd(Size sz)
Point opSub(Size sz)
void opAddAssign(Size sz)
void opSubAssign(Size sz)
struct Size // docmain
/// Construct a new Size.
static Size opCall(int width, int height)
Size sz;
static Size opCall()
Size sz;
Dequ opEquals(Size sz)
Size opAdd(Size sz)
Size result;
Size opSub(Size sz)
Size result;
void opAddAssign(Size sz)
void opSubAssign(Size sz)
Size size() //getter
return Size(width, height);
void size(Size sz) // setter
static Rect opCall(Point location, Size size)
void inflate(Size insz)
Size size(); // getter
final override Size size() // getter
return Size(bm.bmWidth, bm.bmHeight);
Size sz;
Size sz;
final override Size size() // getter
Size result;
final Size getSize(HDC hdc) // package
return Size(getWidth(hdc), getHeight(hdc));
final Size getSize(Graphics g)
return Size(getWidth(g), getHeight(g));
Size sz;
final Size measureText(Dstring text, Font font)
return Size(sz.cx, sz.cy);
final Size measureText(Dstring text, Font font, int maxWidth,
TextFormat fmt)
return Size(rect.right - rect.left, rect.bottom - rect.top);
final Size measureText(Dstring text, Font font, TextFormat fmt)
final Size measureText(Dstring text, Font font, int maxWidth)
final Size measureText(Dstring text, Font font)
final Size getScaleSize(Font f)
Size result;
final Size size() // getter
return Size(_w, _h);
final override Size size() // getter
return Size(bm.bmWidth, bm.bmHeight);
protected override Size defaultSize() // getter
return Size(300, 300);
//Size csz;
final void minimumSize(Size min) // setter
Size changesz;
final Size minimumSize() // getter
final void maximumSize(Size max) // setter
Size changesz;
final Size maximumSize() // getter
Size autoscaleBase;
Size minsz, maxsz; // {0, 0} means none.
wclientsz =

Re: D1: Error: duplicate union initialization for size

2014-08-26 Thread Ali Çehreli via Digitalmars-d-learn

On 08/25/2014 11:36 PM, Jacob Carlborg wrote:

On 26/08/14 00:57, jicman wrote:


Ok, let's try something simpler...  Where can I find the D1 v1.076
compiler error meaning of,

Error: duplicate union initialization for size

for this line,

const Size DEFAULT_SCALE = { 5, 13 };


How does the code for Size look like?



In case it helps you or others to answer, the code appears in D2 as well:

  https://github.com/D-Programming-Language/dmd/blob/master/src/todt.c#L908

The following bug is fixed for D2, which may be the same issue:

  https://issues.dlang.org/show_bug.cgi?id=8902

Ali



Re: D1: Error: duplicate union initialization for size

2014-08-25 Thread Jacob Carlborg via Digitalmars-d-learn

On 26/08/14 00:57, jicman wrote:


Ok, let's try something simpler...  Where can I find the D1 v1.076
compiler error meaning of,

Error: duplicate union initialization for size

for this line,

const Size DEFAULT_SCALE = { 5, 13 };


How does the code for Size look like?

--
/Jacob Carlborg


Re: D1: Error: duplicate union initialization for size

2014-08-25 Thread jicman via Digitalmars-d-learn


Ok, let's try something simpler...  Where can I find the D1 
v1.076 compiler error meaning of,


Error: duplicate union initialization for size

for this line,

const Size DEFAULT_SCALE = { 5, 13 };

thanks.


Re: D1: Error: duplicate union initialization for size

2014-08-24 Thread jicman via Digitalmars-d-learn

On Sunday, 24 August 2014 at 21:54:57 UTC, jicman wrote:

On Sunday, 24 August 2014 at 10:52:38 UTC, bearophile wrote:

jicman:


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.


Can you show the (reduced) definition of Size and 
DEFAULT_SCALE? Even better to show a minimized self-contained 
program that has the problem.


The compiler 1.076 is calling the DFL Control file. These are 
all the lines where DEFAULT_SCALE) is found:


return calcScale(area, toScale, DEFAULT_SCALE);
const Size DEFAULT_SCALE = { 5, 13 };
Size autossz = DEFAULT_SCALE;

Tehse are all the lines where Size is found in all the dfl 
library files:


clientSize = Size(340, 150);
final Size size() // getter
Size result;
Size defaultSize() // getter
return Size(75, 23);
override Size defaultSize() // getter
return Size(120, 23); // ?
final Size clientSize() // getter
final void clientSize(Size sz) // setter
//wclientsz = Size(width, height);
final void size(Size sz) // setter
final Size size() // getter
return wrect.size; // struct Size, not sizeof.
final Size getAutoScaleSize(Font f)
Size result;
final Size getAutoScaleSize()
package final Size _fetchClientSize()
return Size(r.right, r.bottom);
Size defaultSize() // getter
return Size(0, 0);
Size wclientsz;
deprecated final void autoScrollMargin(Size sz) // setter
deprecated final Size autoScrollMargin() // getter
return Size(0, 0);
deprecated final void autoScrollMinSize(Size sz) // setter
deprecated final Size autoScrollMinSize() // getter
return Size(0, 0);
final Size autoScaleBaseSize() // getter
final void autoScaleBaseSize(Size newSize) // setter
	static Size calcScale(Size area, Size toScale, Size fromScale) 
// package

Size calcScale(Size area, Size toScale) // package
final void _scale(Size toScale) // package
void xscale(Control c, Size fromScale)
Size sz;
sz = calcScale(Size(c.left, c.top), toScale, 
fromScale);
final void scrollSize(Size sz) // setter
final Size scrollSize() // getter
const Size DEFAULT_SCALE = { 5, 13 };
//Size scrollmargin, scrollmin;
Size autossz = DEFAULT_SCALE;
Size scrollsz = { 0, 0 };
Point opAdd(Size sz)
Point opSub(Size sz)
void opAddAssign(Size sz)
void opSubAssign(Size sz)
struct Size // docmain
/// Construct a new Size.
static Size opCall(int width, int height)
Size sz;
static Size opCall()
Size sz;
Dequ opEquals(Size sz)
Size opAdd(Size sz)
Size result;
Size opSub(Size sz)
Size result;
void opAddAssign(Size sz)
void opSubAssign(Size sz)
Size size() //getter
return Size(width, height);
void size(Size sz) // setter
static Rect opCall(Point location, Size size)
void inflate(Size insz)
Size size(); // getter
final override Size size() // getter
return Size(bm.bmWidth, bm.bmHeight);
Size sz;
Size sz;
final override Size size() // getter
Size result;
final Size getSize(HDC hdc) // package
return Size(getWidth(hdc), getHeight(hdc));
final Size getSize(Graphics g)
return Size(getWidth(g), getHeight(g));
Size sz;
final Size measureText(Dstring text, Font font)
return Size(sz.cx, sz.cy);
	final Size measureText(Dstring text, Font font, int maxWidth, 
TextFormat fmt)

return Size(rect.right - rect.left, rect.bottom - rect.top);
final Size measureText(Dstring text, Font font, TextFormat fmt)
final Size measureText(Dstring text, Font font, int maxWidth)
final Size measureText(Dstring text, Font font)
final Size getScaleSize(Font f)
Size result;
final Size size() // getter
return Size(_w, _h);
final override Size size() // getter
return Size(bm.bmWidth, bm.bmHeight);
protected override Size defaultSize() // getter
return Size(300, 300);
//Size csz;
final void minimumSize(Size min) // setter
Size changesz;
final Size minimumSize() // getter
final void maximumSize(Size max) // setter
Size changesz;
final Size maximumSize() // getter
Size autoscaleBase;
Size minsz, maxsz; // {0, 0} means 

Re: D1: Error: duplicate union initialization for size

2014-08-24 Thread jicman via Digitalmars-d-learn

On Sunday, 24 August 2014 at 10:52:38 UTC, bearophile wrote:

jicman:


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.


Can you show the (reduced) definition of Size and 
DEFAULT_SCALE? Even better to show a minimized self-contained 
program that has the problem.


The compiler 1.076 is calling the DFL Control file. These are all 
the lines where DEFAULT_SCALE) is found:


return calcScale(area, toScale, DEFAULT_SCALE);
const Size DEFAULT_SCALE = { 5, 13 };
Size autossz = DEFAULT_SCALE;

Tehse are all the lines where Size is found in all the dfl 
library files:


clientSize = Size(340, 150);
final Size size() // getter
Size result;
Size defaultSize() // getter
return Size(75, 23);
override Size defaultSize() // getter
return Size(120, 23); // ?
final Size clientSize() // getter
final void clientSize(Size sz) // setter
//wclientsz = Size(width, height);
final void size(Size sz) // setter
final Size size() // getter
return wrect.size; // struct Size, not sizeof.
final Size getAutoScaleSize(Font f)
Size result;
final Size getAutoScaleSize()
package final Size _fetchClientSize()
return Size(r.right, r.bottom);
Size defaultSize() // getter
return Size(0, 0);
Size wclientsz;
deprecated final void autoScrollMargin(Size sz) // setter
deprecated final Size autoScrollMargin() // getter
return Size(0, 0);
deprecated final void autoScrollMinSize(Size sz) // setter
deprecated final Size autoScrollMinSize() // getter
return Size(0, 0);
final Size autoScaleBaseSize() // getter
final void autoScaleBaseSize(Size newSize) // setter
	static Size calcScale(Size area, Size toScale, Size fromScale) 
// package

Size calcScale(Size area, Size toScale) // package
final void _scale(Size toScale) // package
void xscale(Control c, Size fromScale)
Size sz;
sz = calcScale(Size(c.left, c.top), toScale, 
fromScale);
final void scrollSize(Size sz) // setter
final Size scrollSize() // getter
const Size DEFAULT_SCALE = { 5, 13 };
//Size scrollmargin, scrollmin;
Size autossz = DEFAULT_SCALE;
Size scrollsz = { 0, 0 };
Point opAdd(Size sz)
Point opSub(Size sz)
void opAddAssign(Size sz)
void opSubAssign(Size sz)
struct Size // docmain
/// Construct a new Size.
static Size opCall(int width, int height)
Size sz;
static Size opCall()
Size sz;
Dequ opEquals(Size sz)
Size opAdd(Size sz)
Size result;
Size opSub(Size sz)
Size result;
void opAddAssign(Size sz)
void opSubAssign(Size sz)
Size size() //getter
return Size(width, height);
void size(Size sz) // setter
static Rect opCall(Point location, Size size)
void inflate(Size insz)
Size size(); // getter
final override Size size() // getter
return Size(bm.bmWidth, bm.bmHeight);
Size sz;
Size sz;
final override Size size() // getter
Size result;
final Size getSize(HDC hdc) // package
return Size(getWidth(hdc), getHeight(hdc));
final Size getSize(Graphics g)
return Size(getWidth(g), getHeight(g));
Size sz;
final Size measureText(Dstring text, Font font)
return Size(sz.cx, sz.cy);
	final Size measureText(Dstring text, Font font, int maxWidth, 
TextFormat fmt)

return Size(rect.right - rect.left, rect.bottom - rect.top);
final Size measureText(Dstring text, Font font, TextFormat fmt)
final Size measureText(Dstring text, Font font, int maxWidth)
final Size measureText(Dstring text, Font font)
final Size getScaleSize(Font f)
Size result;
final Size size() // getter
return Size(_w, _h);
final override Size size() // getter
return Size(bm.bmWidth, bm.bmHeight);
protected override Size defaultSize() // getter
return Size(300, 300);
//Size csz;
final void minimumSize(Size min) // setter
Size changesz;
final Size minimumSize() // getter
final void maximumSize(Size max) // setter
Size changesz;
final Size maximumSize() // getter
Size autoscaleBase;
Size minsz, maxsz; // {0, 0} means none.
		wclientsz = Size(wrect.width - ((r.right - r.left)

Re: D1: Error: duplicate union initialization for size

2014-08-24 Thread bearophile via Digitalmars-d-learn

jicman:


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.


Can you show the (reduced) definition of Size and DEFAULT_SCALE? 
Even better to show a minimized self-contained program that has 
the problem.


Bye,
bearophile


Re: D1: Error: duplicate union initialization for size

2014-08-24 Thread Kagamin via Digitalmars-d-learn
Mybe, some fields in Size overlap. If you look at it, you may 
understand, what happens.


D1: Error: duplicate union initialization for size

2014-08-23 Thread jicman via Digitalmars-d-learn


Greetings.

I know that D1 will be deprecated pretty soon and I have a huge 
project based on D1.  I am trying to build everything using the 
latest D1 build (1.076).  I am looking into cleaning up a lot of 
code for this project that uses, dbi, juno and dfl.  I am finding 
this error while compiling the code:


c:\D\dmd1.76\dmd\import\dfl\control.d(7634): Error: duplicate 
union initialization for size


This is line 7634:

const Size DEFAULT_SCALE = { 5, 13 };

What does the error say and how can I fix it?  Thanks.

josé