memcpy in D

Marco Leise Marco.Leise at gmx.de
Sun Jun 30 22:22:36 PDT 2013


... or alternatively:

// Simple integers can be compile-time literals (i.e. C's #define)
enum ADDRESS_BUS_SIZE = 20; // 2^20 address bus
// In D it is more ideomatic to put the array length first.
// For example this wouldn't work: byte x, *y, memory[1 << ADDRESS_BUS_SIZE];
byte[1 << ADDRESS_BUS_SIZE] memory;

void main()
{
	ushort val = 12345;
	ushort* base = cast(ushort*) &memory[0x12340];

	foreach (i; 0 .. 5)
		base[i] = val++;
	
	foreach (i; 0 .. 5)
		writefln("%04x", base[i]);
}

-- 
Marco



More information about the Digitalmars-d-learn mailing list