Thread overview | |||||
---|---|---|---|---|---|
|
November 20, 2008 Compilation error when using a extern function ? | ||||
---|---|---|---|---|
| ||||
Hello, I'm on DMD 1.036. When I'm compiling this code : // -------------CODE----------------------- enum ColorValues:uint { AliceBlue = 0xF0F8FFFF ,AntiqueWhite = 0xF8ECD8FF ,Aqua = 0x00FFFFFF ,Aquamarine = 0x80FFD0FF ,Azure = 0xF0FFFFFF ,Beige = 0xF8F4E0FF ,Bisque = 0xFFE4C8FF [...] Color convertToColor(uint val) { ubyte[4] colorVal = *cast(ubyte*)&val; return Color( colorVal[0] ,colorVal[1] ,colorVal[2] ,colorVal[3] ); } class DFLCalendar:Panel { // Graphicals objects protected { // Colors default preferences : const Color colorPanMonth = convertToColor(cast(uint)ColorValues.MidnightBlue); const Color colorPanDays = convertToColor(cast(uint)ColorValues.White); const uint heightPanMonth = 16 ; const uint widthButChangeMonth = 10; [...] // -------------END CODE------------------- The compiler return me the error : tools\gui\tools\DFLCalendar.d(29): Error: cannot evaluate convertToColor(404254975u) at compile time Line 29 corresponds to "const Color colorPanMonth = convertToColor(cast(uint)ColorValues.MidnightBlue);" Thanks in advance for your help, TSalm |
November 20, 2008 Re: Compilation error when using a extern function ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to tsalm | 21.11.08 в 01:57 tsalm в своём письме писал(а):
> Hello,
>
>
> I'm on DMD 1.036.
> When I'm compiling this code :
>
> // -------------CODE-----------------------
>
>
> enum ColorValues:uint
> {
> AliceBlue = 0xF0F8FFFF
> ,AntiqueWhite = 0xF8ECD8FF
> ,Aqua = 0x00FFFFFF
> ,Aquamarine = 0x80FFD0FF
> ,Azure = 0xF0FFFFFF
> ,Beige = 0xF8F4E0FF
> ,Bisque = 0xFFE4C8FF
>
> [...]
>
>
> Color convertToColor(uint val)
> {
> ubyte[4] colorVal = *cast(ubyte*)&val;
>
> return Color( colorVal[0]
> ,colorVal[1]
> ,colorVal[2]
> ,colorVal[3]
> );
> }
>
> class DFLCalendar:Panel
> {
> // Graphicals objects
> protected
> {
> // Colors default preferences :
> const Color colorPanMonth = convertToColor(cast(uint)ColorValues.MidnightBlue);
> const Color colorPanDays = convertToColor(cast(uint)ColorValues.White);
> const uint heightPanMonth = 16 ;
> const uint widthButChangeMonth = 10;
>
> [...]
> // -------------END CODE-------------------
>
> The compiler return me the error :
>
> tools\gui\tools\DFLCalendar.d(29): Error: cannot evaluate convertToColor(404254975u) at compile time
>
> Line 29 corresponds to "const Color colorPanMonth = convertToColor(cast(uint)ColorValues.MidnightBlue);"
>
>
> Thanks in advance for your help,
> TSalm
I wouldn't recommend you to use that trick, you may have problems with Endianess. But in case you don't care I would suggest you to use the following "cast" instead:
union ColorProxy {
uint color;
struct {
ubyte red;
ubyte green;
ubyte blue;
ubyte alpha;
}
}
ColorProxy proxy;
proxy.color = ColorValues.Aqua;
return Color(proxy.red, proxy.green, proxy.blue, proxy.alpha);
|
November 21, 2008 Re: Compilation error when using a extern function ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Le Fri, 21 Nov 2008 00:34:03 +0100, Denis Koroskin <2korden@gmail.com> a écrit:
> union ColorProxy {
> uint color;
> struct {
> ubyte red;
> ubyte green;
> ubyte blue;
> ubyte alpha;
> }
> }
> ColorProxy proxy;
> proxy.color = ColorValues.Aqua;
> return Color(proxy.red, proxy.green, proxy.blue, proxy.alpha);
Yes it's a better way.
Thanks.
|
Copyright © 1999-2021 by the D Language Foundation