Re: Initializing statically-allocated arrays within templates

2018-09-26 Thread M88
Scoped includes and constants areawesome. On Tuesday, September 25, 2018 at 3:28:05 PM UTC-4, M88 wrote: > > Hello, > > I was wondering if it's possible to use a template to define the size of a > statically allocated array in a template. > > An example (that won't compile) is: > >

Re: Initializing statically-allocated arrays within templates

2018-09-25 Thread Julian Fondren
Slightly neater. Note that you can have cover (multiple; expressions) with a single where {} #include "share/atspre_staload_hats." implement main0() = example() where { #define example$bufsz 100 #include "./testarr.hats" } On Tuesday, September 25, 2018 at 3:46:17 PM UTC-5, Julian Fondren

Re: Initializing statically-allocated arrays within templates

2018-09-25 Thread gmhwxi
I see. Then there isn't really a way to do this as the 'sz' in @[a?][sz] is static. I will keep an eye on it. Maybe I can find a way to support it in ATS3. On Tuesday, September 25, 2018 at 7:01:48 PM UTC-4, M88 wrote: > > > I get an error during C compilation, ATSERRORarrdim_unknown, when I

Re: Initializing statically-allocated arrays within templates

2018-09-25 Thread M88
I get an error during C compilation, ATSERRORarrdim_unknown, when I try to use a template function. Thanks Julian -- that's a decent solution. On Tuesday, September 25, 2018 at 3:28:05 PM UTC-4, M88 wrote: > > Hello, > > I was wondering if it's possible to use a template to define the size of

Re: Initializing statically-allocated arrays within templates

2018-09-25 Thread Hongwei Xi
You can use a function template: fun {} example$bufsz() : [n:pos] size_t n Because of inlining, you should get what you wanted in the first place. On Tue, Sep 25, 2018 at 3:28 PM M88 wrote: > Hello, > > I was wondering if it's possible to use a template to define the size of a > statically

Re: Initializing statically-allocated arrays within templates

2018-09-25 Thread Julian Fondren
An option. testarr.dats: #include "share/atspre_staload.hats" local #define example$bufsz 100 in #include "./testarr.hats" end implement main0() = example() testarr.hats: extern fun {a:t@ype} example(): void implement {a} example() = let val sz = example$bufsz var buf =