digitalmars.D.learn - Compilation error when using a extern function ?
- tsalm (45/45) Nov 20 2008 Hello,
- Denis Koroskin (16/61) Nov 20 2008 I wouldn't recommend you to use that trick, you may have problems with
- tsalm (4/16) Nov 21 2008 Yes it's a better way.
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
Nov 20 2008
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, TSalmI 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);
Nov 20 2008
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.
Nov 21 2008