Enumeration symbols values limits lazarus / 62-General ---------------------------------------------------------------------- fcu · 2022-01-07 21:23 Hi this code works fine with fpc 3.2 but not with 3.3 (trunk) is there a workaround for this error ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  type   TD3DDevType = (    D3DDEVTYPE_HAL = 1,    D3DDEVTYPE_REF = 2,    D3DDEVTYPE_SW = 3,    D3DDEVTYPE_NULLREF = 4,    D3DDEVTYPE_FORCE_DWORD = $ffffffff // Error: Enumeration symbols can only have values in the range of -2^31 to 2^31-1  ); ---------------------------------------------------------------------- rvk · 2022-01-07 23:21 And are you sure ord(D3DDEVTYPE_FORCE_DWORD) evaluated back to $ffffffff in the older version?? From https://wiki.freepascal.org/User_Changes_Trunk QuoteExplicit values for enumeration types are limited to low(longint) ... high(longint) Old behavior: The compiler accepted every integer value as explicit enumeration value. The value was silently reduced to the longint range if it fell outside of that rangeNew behavior: The compiler throws an error (FPC mode) or a warning (Delphi mode) if an explicit enumeration value lies outside the longint range.Reason: Type TEnum = (a = $ffffffff); resulted in an enum with size 1 instead of 4 as would be expected, because $ffffffff was interpreted as "-1".Remedy: Add Longint typecasts to values outside the valid range of a Longint.So you could do this: QuoteRemedy: Add Longint typecasts to values outside the valid range of a Longint. This seems to compile: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type TD3DDevType = (   D3DDEVTYPE_HAL = 1,   D3DDEVTYPE_REF = 2,   D3DDEVTYPE_SW = 3,   D3DDEVTYPE_NULLREF = 4,   D3DDEVTYPE_FORCE_DWORD = LongInt($ffffffff) // Error: Enumeration symbols can only have values in the range of -2^31 to 2^31-1 ); (Not sure if it gives the desired result in your code.) ---------------------------------------------------------------------- PascalDragon · 2022-01-08 11:01 Quote from: rvk on January 08, 2022, 12:21:52 am(Not sure if it gives the desired result in your code.) Yes, it does. Another way - as D3DDEVTYPE_FORCE_DWORD is clearly intended to only ensure the correct size of the enum - is to use MinEnumSize: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program tenum; {$mode objfpc} type TD3DDevType = (   D3DDEVTYPE_HAL = 1,   D3DDEVTYPE_REF = 2,   D3DDEVTYPE_SW = 3,   D3DDEVTYPE_NULLREF = 4,   D3DDEVTYPE_FORCE_DWORD = LongInt($ffffffff) );  {$Push} {$MinEnumSize 4} TD3DDevType2 = (   D3DDEVTYPE2_HAL = 1,   D3DDEVTYPE2_REF = 2,   D3DDEVTYPE2_SW = 3,   D3DDEVTYPE2_NULLREF = 4 ); {$Pop}  begin  Writeln(SizeOf(TD3DDevType)); // will write 4  Writeln(SizeOf(TD3DDevType2)); // will write 4 as wellend. Yes, that means that D3DDEVTYPE_FORCE_DWORD would not be available, but it isn't a “valid” value for the API anyway. ---------------------------------------------------------------------- Thaddy · 2022-01-09 14:36 Working with bits on all integer types (signed or not) is supported in an easy way by using the helpers from sysutils. This does not fully apply to Pascal enumerations, though. See syshelph.inc So if you need the bits for an external API that should not be very difficult. ---------------------------------------------------------------------- PascalDragon · 2022-01-10 12:46 Quote from: jamie on January 09, 2022, 02:52:09 pmit would be nice if one could use unsigned values in there so one could use bit fields in a DWORD or word for example to represent closely to what you see in many of API's and third party libs and C code etc.. No. Enumeration types are signed. This has always been this way and it will stay this way and it is also Delphi compatible. Quote from: Thaddy on January 09, 2022, 03:36:57 pmWorking with bits on all integer types (signed or not) is supported in an easy way by using the helpers from sysutils. This does not fully apply to Pascal enumerations, though. See syshelph.inc So if you need the bits for an external API that should not be very difficult. This is not about working with bits, so please don't mix in unrelated topics.