Mercury Bugs - mercury
View Issue Details
0000158mercuryBugpublic2010-08-18 14:312010-08-19 17:36
Reportercolanderman 
Assigned Towangp 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000158: char constants do not unify
DescriptionFor some reason, this code:

if det_from_int(255) = '\xFF\' then print("succeed\n", !IO) else print("fail\n", !IO)

prints "fail". This code however:

if 255 = to_int('\xFF\') then print("succeed\n", !IO) else print("fail\n", !IO)

prints "succeed" as expected.
Additional InformationMercury 10.04, Debian Linux 32-bit
TagsNo tags attached.
Attached Files? charbug.m (326) 2010-08-18 14:31
https://bugs.mercurylang.org/file_download.php?file_id=106&type=bug

Notes
(0000279)
wangp   
2010-08-18 15:32   
Thanks. This bug affects 8-bit character literals in low-level C grades.

The LLDS doesn't differentiate between integer and character constants, and the 0xff character ends up in the C source code as (MR_Integer)255 instead of (MR_Char)255. MR_Char is signed (depends on the compiler) so we end up comparing 255 with -1.

Issue History
2010-08-18 14:31colandermanNew Issue
2010-08-18 14:31colandermanFile Added: charbug.m
2010-08-18 15:32wangpNote Added: 0000279
2010-08-19 17:36wangpStatusnew => resolved
2010-08-19 17:36wangpResolutionopen => fixed
2010-08-19 17:36wangpAssigned To => wangp