Compilation error when using a extern function ?
Denis Koroskin
2korden at gmail.com
Thu Nov 20 15:34:03 PST 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,
> 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);
More information about the Digitalmars-d-learn
mailing list