const
ASIGNATURE = DWORD('abcd');
Currently FPC will not accept the above constant. Since 'abcd' is 4 bytes
Perhaps internally 'abcd' isn't represented as 4 bytes... It may be treated as a string of unicode characters, and the compiler doesn't bother to find out if all characters are also valid ASCII characters. This seems valid, though not a constant and a bit wordy:
var
abcd_str : array[0..3] of AnsiChar = 'abcd'; abcd : DWord absolute abcd_str;
why simply don't write as natural language Pascal impose?
const
ASIGNATURE = DWORD($abcd);
'abcd' is
#$61 + #$62 + #$63 + #$64, it is not
#$A + #$B + #$C + #$D.
'abcd' as a DWord would be the integer value $64636261 (on little-endian machines).
It has always seemed strange to me that Pascal, known for being very strongly typed, refuses to enforce distinctness between types explicitly marked as such (think type <NEWLINE> type HWND = HANDLE - what's the purpose of the second type if it doesn't even make HWND distinct from HANDLE?)
It could be done with records or classes that encapsulate the actual value, though it's a lot more to type. There's also the question if the compiler is still able to pass these constructs to a subroutine via CPU registers.
The fact that DWORD('abcd') is possible at all is beyond cursed
since when are casts allowed to dereference pointers?
Why would 'abcd' be a pointer?
How about this?
const
ASIGNATURE = DWORD($61626364); // 'abcd'
begin
Rec.Signature := NToBE(ASIGNATURE);
end
That would require manually translating these strings...