enum ubyte[] vs enum ubyte[3]

Jonathan M Davis jmdavisProg at gmx.com
Mon Dec 20 03:15:28 PST 2010


On Monday 20 December 2010 01:26:16 Johannes Pfau wrote:
> Hi,
> I'm currently patching Ragel (http://www.complang.org/ragel/) to generate
> D2 compatible code. Right now it creates output like this for static
> arrays:
> ------------------------
> enum ubyte[] _parseResponseLine_key_offsets = [
> 	0, 0, 17, 18, 37, 41, 42, 44,
> 	50, 51, 57, 58, 78, 98, 118, 136,
> 	138, 141, 143, 146, 148, 150, 152, 153,
> 	159, 160, 160, 162, 164
> ];
> ------------------------
> Making it output "enum ubyte[30]" would be more complicated, so I wonder
> if there's a difference between "enum ubyte[]" and "enum ubyte[30]"?

ubyte[] is a dynamic array. ubyte[30] is a static array. They are inherently 
different types. The fact that you're dealing with an enum is irrelevant. So, the 
code that you're generating is _not_ a static array. It's a dynamic array. This 
is inherently different from C or C++ where having [] on a type (whether it has a 
number or not) is _always_ a static array.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list