Confusion about static arrays

Rick Mann rmann-d-lang at latencyzero.com
Sat Jan 27 18:55:55 PST 2007


I had a little hiccup earlier when I tried to do this:

	static EventTypeSpec[1] events =
	[
		{ EventClass.kEventClassWindow, kEventWindowBoundsChanged }
	];
	writefln("events: 0x%x", events);

(EventTypeSpec is a struct with two uint members).

This resulted in a bus error inside writefln(). Someone pointed out that I should pass events.ptr, which works. However, from the examples in (http://www.digitalmars.com/d/arrays.html). For example, it says that static arrays are analogous to C arrays. It also suggests this:

int* p;
int[3] s;
int[] a;

p = s;		// p points to the first element of the array s.
p = a;		// p points to the first element of the array a.

In both cases, assigning from s or a results in something pointing to the first element of s and a. 

I guess I have two questions:

a) why would passing "events" to writefln() (with that specific format specifier) cause it all to crash

b) Is the spec web page incorrect (or is it reasonable to be mislead by its wording) when it seems to imply that one can simply pass the name of the array around, rather than .ptr?

Thanks!



More information about the Digitalmars-d-learn mailing list