www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 509] New: [wd]char[1] does not convert to [wd]char

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=509

           Summary: [wd]char[1] does not convert to [wd]char
           Product: D
           Version: 0.174
          Platform: PC
               URL: http://www.digitalmars.com/d/arrays.html
        OS/Version: Windows
            Status: NEW
          Keywords: spec
          Severity: normal
          Priority: P4
         Component: www.digitalmars.com
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: deewiant gmail.com


The Arrays spec, under the "Strings" section, has the following example code:

wchar w;
w = \r; // w is assigned the carriage return wchar character

This code does not compile: cannot implicitly convert expression ("\x0d") of
type char[1] to wchar. Trying to explicitly cast it to wchar[1], wchar[], or
wchar also fails with similar error messages.

Yet, the spec says right above this code that "[s]trings a single character in
length can also be exactly converted to a char, wchar or dchar constant".

Which is correct? To solve, change compiler behaviour to make the code compile
and then change the 'w = "b"[0]' part of the code to 'w = "b"', or remove the
sentence quoted and change the 'w = \r' line to 'w = \r[0]'.


-- 
Nov 15 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=509


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com




------- Comment #1 from smjg iname.com  2006-11-16 19:25 -------
Why

    w = \r[0]

rather than

    w = '\r';

?


-- 
Nov 16 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=509





------- Comment #2 from deewiant gmail.com  2006-11-17 06:45 -------
(In reply to comment #1)
 Why
 
     w = \r[0]
 
 rather than
 
     w = '\r';
 
 ?
 
Because there's already an example of assigning that way ("w = 'b'"). This example, in my humble opinion, is useful even if the [0] is added since it shows how quotes around the \r aren't necessary. --
Nov 17 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=509


deewiant gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from deewiant gmail.com  2006-12-03 03:49 -------
Spec corrected for DMD 0.176.


-- 
Dec 03 2006