Thread overview
[Bug 123] New: Use of function, modulus, and dollar sign (length) fails to compile with static and const
May 02, 2006
d-bugmail
May 02, 2006
d-bugmail
May 15, 2006
Thomas Kuehne
May 02, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=123

           Summary: Use of function, modulus, and dollar sign (length) fails
                    to compile with static and const
           Product: D
           Version: 0.157
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: link-failure
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: CppCoder@gmail.com


uint intRes()
{
        return 4;
}

int main()
{
        static const char []foo = "abc123";
        //everything works as expected if static and const are removed.
        writefln( "%c", foo[intRes() % $] );

        return 0;
}

linking fails:
main.obj(main)
 Error 42: Symbol Undefined _Dmain8__dollark
--- errorlevel 1


-- 

May 02, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=123





------- Comment #1 from ddparnell@bigpond.com  2006-05-01 21:25 -------
This works...
// --------------
import std.stdio;
uint intRes()
{
        return 4;
}
const char [6]foo = "abc123";
void main()
{
    writefln( foo[intRes() % length] );
}
// --------------


This fails...
// --------------
import std.stdio;
uint intRes()
{
        return 4;
}
const char []foo = "abc123";
void main()
{
    writefln( foo[intRes() % length] );
}
// --------------

This works...
// --------------
import std.stdio;
uint intRes()
{
        return 4;
}
const char []foo = "abc123";
void main()
{
    writefln( foo[intRes() % foo.length] );
}
// --------------

This works...
// --------------
import std.stdio;
uint intRes()
{
        return 4;
}
char []foo = "abc123";
void main()
{
    writefln( foo[intRes() % length] );
}
// --------------

This works...
// --------------
import std.stdio;
uint intRes()
{
        return 4;
}
const char []foo = "abc123";
void main()
{
    writefln( foo[4 % length] );
}
// --------------


-- 

May 15, 2006
d-bugmail@puremagic.com schrieb am 2006-05-02:
> http://d.puremagic.com/bugzilla/show_bug.cgi?id=123

> uint intRes()
> {
>         return 4;
> }
>
> int main()
> {
>         static const char []foo = "abc123";
>         //everything works as expected if static and const are removed.
>         writefln( "%c", foo[intRes() % $] );
>
>         return 0;
> }
>
> linking fails:
> main.obj(main)
>  Error 42: Symbol Undefined _Dmain8__dollark
> --- errorlevel 1

Added to DStress as http://dstress.kuehne.cn/run/l/length_10_A.d http://dstress.kuehne.cn/run/l/length_10_B.d http://dstress.kuehne.cn/run/l/length_10_C.d http://dstress.kuehne.cn/run/l/length_10_D.d http://dstress.kuehne.cn/run/l/length_10_E.d http://dstress.kuehne.cn/run/l/length_10_F.d http://dstress.kuehne.cn/run/l/length_10_G.d http://dstress.kuehne.cn/run/l/length_10_H.d http://dstress.kuehne.cn/run/l/length_10_I.d http://dstress.kuehne.cn/run/l/length_10_J.d

Thomas