www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1884] New: manifest constants for strings

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

           Summary: manifest constants for strings
           Product: D
           Version: 2.011
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: ddparnell bigpond.com


The code below does not work as I expected it to.

//-----------------
import std.stdio;

void main()
{
    enum string foo = "qwerty";
    std.stdio.writefln("'%s'", foo);    
    foreach(int i, char c; foo)
        writefln("[%s]%s", i, cast(int)c);

    enum fob = "qwerty";
    std.stdio.writefln("'%s'", fob);    
    foreach(int i, char c; fob)
        writefln("[%s]%s", i, cast(int)c);

    const bar = "qwerty";            
    std.stdio.writefln("'%s'", bar);    
    foreach(int i, char c; bar)
        writefln("[%s]%s", i, cast(int)c);
}
//-----------------

I was expecting three identical strings to printout plus each character to be
correct. Instead I got this ...

'qwerty'
[0]176
[1]236
[2]65
'    ÿý'
[0]0
[1]0
[2]0
[3]0
[4]152
[5]236
'qwerty'
[0]113
[1]119
[2]101
[3]114
[4]116
[5]121

Which seems to me that only the form "const x " works.


-- 
Feb 29 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1884





------- Comment #1 from ddparnell bigpond.com  2008-02-29 20:46 -------
And if you think that was stringe, try this example ...

//-------------
import std.stdio;


void main()
{


    enum string foo = "qwerty";
    std.stdio.writefln("'%s'", foo);    
    foreach(int i, char c; foo)
        writefln("[%s]%s", i, cast(int)c);


    enum fob = "qwerty";
    std.stdio.writefln("'%s'", fob);    
    foreach(int i, char c; fob)
        writefln("[%s]%s", i, cast(int)c);


    const bar = "qwerty";            
    std.stdio.writefln("'%s'", bar);    
    foreach(int i, char c; bar)
        writefln("[%s]%s", i, cast(int)c);

    std.stdio.writefln("'%s'", "qwerty");    
    foreach(int i, char c; "qwerty")
        writefln("[%s]%s", i, cast(int)c);
}
//---------


-- 
Feb 29 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1884


torhu yahoo.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |torhu yahoo.com




------- Comment #2 from torhu yahoo.com  2008-02-29 21:03 -------
Looks like it's related to 1794.

http://d.puremagic.com/issues/show_bug.cgi?id=1794


-- 
Feb 29 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1884





------- Comment #3 from bugzilla digitalmars.com  2008-03-07 00:39 -------
Fixed dmd 2.012


-- 
Mar 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1884


sardonicpresence gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sardonicpresence gmail.com




------- Comment #4 from sardonicpresence gmail.com  2008-03-26 08:35 -------
What I assume is the same issue still occurs within structs as of 2.012 e.g.

//-----------------
import std.stdio;

struct Test
{
  public string Text;
}

enum Test test = { Text: "test" };

void main()
{
  std.stdio.writefln(test);
}
//-----------------

This results in the following output:

' âA ÓâA `äA ►ëA └ëA  øA á£A ►×A ǃA  ñA ­ñA ­ªA '


-- 
Mar 26 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1884





------- Comment #5 from sardonicpresence gmail.com  2008-03-26 08:37 -------
Sorry that should have been "std.stdio.writefln("'%s'", test.Text);".


-- 
Mar 26 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1884


clugdbug yahoo.com.au changed:

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




------- Comment #6 from clugdbug yahoo.com.au  2009-04-18 01:36 -------
Neil's bug is actually totally different, and not related to strings in any
way.--> Bug #2850.
The original bug is fixed.


-- 
Apr 17 2009