www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23031] New: importC: hex character escapes should be variable

https://issues.dlang.org/show_bug.cgi?id=23031

          Issue ID: 23031
           Summary: importC: hex character escapes should be variable
                    length
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: ImportC
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: duser neet.fi
                CC: duser neet.fi

#include <assert.h>
_Static_assert(sizeof("\x1") == 2, ""); // Error: escape hex sequence has 1 hex
digits instead of 2
_Static_assert(sizeof("\x20") == 2, "");
_Static_assert(sizeof("\x020") == 2, ""); // fails, parsed as [0x02, '0']
_Static_assert(sizeof("\x0020") == 2, ""); // fails, parsed as [0x00, '2', '0']
int main()
{ 
        assert( "\x1"[0] == 1 ); // Error: escape hex sequence has 1 hex digits
instead of 2
        assert( "\x20"[0] == 0x20 );
        assert( "\x020"[0] == 0x20 );
        assert( "\x0020"[0] == 0x20 );
}



 7. Each octal or hexadecimal escape sequence is the longest sequence of
characters that can constitute the escape sequence.
octal escapes are 1-3 characters, hex ones are 1-infinity ("hexadecimal-escape-sequence" in the syntax listing is recursive) --
Apr 17 2022