Bug 13658 – Array length type is not size_t

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2014-10-26T01:33:00Z
Last change time
2014-10-27T13:39:39Z
Assigned to
nobody
Creator
markisaa

Comments

Comment #0 by markisaa — 2014-10-26T01:33:41Z
According to the language reference at: http://dlang.org/arrays, the .length property of an array is meant to return a value with type size_t. That is not the case on Windows with dmd 2.066. This issue is more widespread than just the .length property; I discovered this by trying to index an array with a ulong (same type as size_t) and found dmd yelling about implicit conversions to uint. The problematic code was of the form: myArray[thingThatReturnsULong() - 1 - 1]; For reference, the precise line of code that breaks: https://github.com/facebook/flint/blob/master/Checks.d#L3016 I confirmed the types of size_t, myArray.length, and a few other things using pragma(msg, typeof(thing)); For what it's worth, if you pointed me at roughly the write part of the code that needed fixing, I would gladly make the change; I wasn't able to find the relevant code in druntime and the dmd repo is a mystery to me.
Comment #1 by dfj1esp02 — 2014-10-27T09:02:03Z
size_t is not always ulong, it's uint in 32-bit mode and ulong in 64-bit mode.
Comment #2 by aldacron — 2014-10-27T11:26:00Z
This comes from D's compatibility with C. size_t does not have a predefined type size (in the C99 standard it is defined as an unsigned integer of at least 16 bytes in size). What you find on modern compilers is that it will be 32-bits on 32-bit platforms and 64-bits on 64-bit platforms. So in D it is an alias for uint on 32-bit and ulong on 64.
Comment #3 by dfj1esp02 — 2014-10-27T11:37:23Z
(In reply to Mark Isaacson from comment #0) > For reference, the precise line of code that breaks: > https://github.com/facebook/flint/blob/master/Checks.d#L3016 size_t[] specialTokenHead = []; size_t[] lhsExprHead = [0];
Comment #4 by schveiguy — 2014-10-27T13:08:22Z
(In reply to Mike Parker from comment #2) > (in the C99 standard it is defined as an unsigned integer of at > least 16 bytes in size). bit, byte, same thing pretty much ;)
Comment #5 by aldacron — 2014-10-27T13:39:39Z
(In reply to Steven Schveighoffer from comment #4) > (In reply to Mike Parker from comment #2) > > (in the C99 standard it is defined as an unsigned integer of at > > least 16 bytes in size). > > bit, byte, same thing pretty much ;) Yeah, yeah. You say potato... :)