[Issue 15153] CTFE failes to access second dimension of static arrays
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Oct 4 11:51:48 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15153
ag0aep6g at gmail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |ag0aep6g at gmail.com
Resolution|--- |INVALID
--- Comment #1 from ag0aep6g at gmail.com ---
(In reply to tobias.marstaller from comment #0)
> But even if the array sizes are explicitly given, the error stays:
>
> -----------------------------------------------------------------------------
> ---
> static int[2][2] staticTable = [[1, 2], [3, 4]];
> static int[2][2] staticallyDerivedTable = deriveTable(staticTable);
>
> static int[2][2] deriveTable(int[2][2] table)
> {
> int nRows = table.length;
> int nCols = table[0].length;
> int[nCols][nRows] newTable;
>
> // ... do something
>
> return newTable;
> }
> -----------------------------------------------------------------------------
> ---
>
>
> This might be related to #2569;
>
> AFAICT my code is correct; in both cases the required information is
> available
> at compile time. table.length does not throw an error so i guess the basics
> are working fine already.
It's true that table.length is a static value. It's known at compile time, and
the compiler is aware of that. You can use it for static array lengths.
But nRows is a run time variable. Its value may actually be a compile time
constant, but the compiler doesn't try to find out. This is working as
designed.
You can use enums instead of variables:
----
enum int[2][2] staticTable = [[1, 2], [3, 4]];
static int[2][2] staticallyDerivedTable = deriveTable(staticTable);
static int[2][2] deriveTable(int[2][2] table)
{
enum size_t nRows = table.length;
enum size_t nCols = table[0].length;
int[nCols][nRows] newTable;
// ... do something
return newTable;
}
----
I'm closing this as INVALID. Please reopen and/or make a thread on
http://forum.dlang.org/group/general if you disagree.
--
More information about the Digitalmars-d-bugs
mailing list