Re: Translating C "static arrays" into D?

ketmar ketmar at ketmar.no-ip.org
Mon Feb 26 18:31:43 UTC 2018


H. S. Teoh wrote:

> On Mon, Feb 26, 2018 at 08:07:11PM +0200, ketmar via Digitalmars-d wrote:
> [...]
>> in C, arrays are *always* decaying to pointers. so
>> 	void foo (int x[2])
>> is the same as
>> 	void foo (int* x)
>> `[2]` is purely informational.
>> that is, in D it will be:
>> 	alias mytype = double*;
>
> Actually, that doesn't work, because in the struct declaration it will
> be wrong:
>
> 	// C
> 	struct S {
> 		double[5] x; // actually occupies the space of 5 doubles
> 	}
>
> 	// D
> 	struct S {
> 		double* x; // occupies the space of 1 pointer (wrong)
> 	}

yeah, sorry. somehow i completely missed structs.


More information about the Digitalmars-d mailing list