Fixing C's Biggest Mistake
H. S. Teoh
hsteoh at qfbox.info
Thu Jan 5 22:09:15 UTC 2023
On Thu, Jan 05, 2023 at 10:03:10PM +0000, areYouSureAboutThat via Digitalmars-d wrote:
> On Thursday, 5 January 2023 at 21:18:00 UTC, IGotD- wrote:
> > On Thursday, 5 January 2023 at 21:08:28 UTC, areYouSureAboutThat wrote:
> > >
> > > int[] myStaticArray = [0, 1].staticArray;
> > > static assert(is(typeof(myStaticArray) == int[2]));
> > >
> > >
> > > Is there any reason the compiler cannot be made to do this?
> >
> > In your example, wouldn't myStaticArray be a slice?
>
> how can this possibly be misinterpreted??
>
> int[] myStaticArray = [0, 1].staticArray;
>
> the '.staticArray' provides all the context needed to understand what
> type is being created.
`int[]` is a slice. The static array is written as `int[2]`.
This is valid (though not exactly a good idea):
// Take a slice of a static array
int[] myStaticArray = [0, 1].staticArray[];
T
--
Lottery: tax on the stupid. -- Slashdotter
More information about the Digitalmars-d
mailing list