Bug 16261 – dmd -profile & nativeToLittleEndian() --> wrong result
Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2016-07-10T09:59:51Z
Last change time
2019-12-05T07:04:33Z
Assigned to
No Owner
Creator
Johan Holmberg
Comments
Comment #0 by johan556 — 2016-07-10T09:59:51Z
When the -profile flag is given to dmd, a call to nativeToLittleEndian() gives wrong result. The following code works without -profile:
import std.stdio;
import std.bitmanip;
int
main(string[] argv)
{
int value = 42;
auto res = nativeToLittleEndian(value);
writeln("nativeToLittleEndian(", value, ") = ", res);
// expected output: nativeToLittleEndian(42) = [42, 0, 0, 0]
return 0;
}
but with -profile it prints what seems to be garbage bytes, even different values each time the program is executed.
The version of the compiler was "DMD64 D Compiler v2.071.1", and I have also built DMD from source today getting the same problem.
I also tried the example code in the documentation of nativeToLittleEndian() at dlang.org. There too, when I build with -profile, the code does not work (gives an assert).
Comment #1 by dushibaiyu — 2016-08-09T05:07:24Z
nativeToBigEndian aslo erro!
import std.stdio;
import std.bitmanip;
enum ushort type = 100;
void main()
{
ubyte[2] udt = nativeToBigEndian(type);
writeln("100 as nativeToBigEndian : ", udt);
ushort uy = bigEndianToNative!(ushort)(udt);
writeln("uy = : ", uy);
}
the rulst:
100 as nativeToBigEndian : [13, 21]
uy = : 3349
Comment #2 by bugzilla — 2019-12-05T07:04:33Z
I just seen, that this is attributed as Mac OS X. Is this a Max OS X only bug? If yes, I'm sorry, we should reopen it...