Setting a hard limit on slice size, is this possible?

2021-08-06 Thread james.p.leblanc via Digitalmars-d-learn
I am aware of the "capacity" concept with slices. But, I would like to know if it is possible to set a hard limit on a slice size. I prefer it to error and crash instead of a doing an extension or reallocation. I understand my question screams of "convoluted thinking". But, I need to align my

Re: Conditional compilation: Which version identifier for release code ? version(assert) ?

2021-08-06 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 August 2021 at 11:01:56 UTC, Adam D Ruppe wrote: On Thursday, 5 August 2021 at 09:18:08 UTC, wjoe wrote: If it's to be determined whether or not the code is being compiled in debug or release mode, i.e. e.g. the dmd ```-release``` You should never use the -release flag. It

Re: Conditional compilation: Which version identifier for release code ? version(assert) ?

2021-08-06 Thread wjoe via Digitalmars-d-learn
On Thursday, 5 August 2021 at 11:54:38 UTC, Mike Parker wrote: On Thursday, 5 August 2021 at 10:43:01 UTC, wjoe wrote: Could you elaborate on ```version(assert)``` a bit more, please ? Like I compiled with ```-release, -g``` and without the 2 options but the ```assert``` branch was always

Re: best/proper way to declare constants ?

2021-08-06 Thread someone via Digitalmars-d-learn
On Friday, 6 August 2021 at 04:57:02 UTC, Ali Çehreli wrote: May I humbly suggest names like Location instead of structureLocation to make refactoring even more straightforward. ;) just renamed everything like following: - sWhatever for structures - iWhatever for interfaces - cWhatever for

Re: Generating C Headers From D Code

2021-08-06 Thread Jack Stouffer via Digitalmars-d-learn
On Thursday, 5 August 2021 at 17:02:33 UTC, Tejas wrote: On Thursday, 5 August 2021 at 16:28:35 UTC, Jack Stouffer wrote: I need to generate plain C99 .h files from a D module's extern(C) declarations, so that I can link a DMD generated .o file with a C code base. Are there any automated tools

Re: Generating C Headers From D Code

2021-08-06 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 5 August 2021 at 16:28:35 UTC, Jack Stouffer wrote: I know the compiler has C++ header generation Your best bet is probably to use this and just do the slight modifications to turn it from C++ into C. dmd -HC followed by a modification script to rip some of the stuff out

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 August 2021 at 10:50:19 UTC, james.p.leblanc wrote: I am aware of the "capacity" concept with slices. But, I would like to know if it is possible to set a hard limit on a slice size. I prefer it to error and crash instead of a doing an extension or reallocation. I don't think

Tracy

2021-08-06 Thread JG via Digitalmars-d-learn
There was a message a while back (https://forum.dlang.org/post/fyakhpjbcpzqegfev...@forum.dlang.org) about adding support for tracy. When I asked a question about compile time performance I received the following instructions: https://forum.dlang.org/post/eevoyuwhbuycyzgxs...@forum.dlang.org

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 August 2021 at 19:03:53 UTC, Tejas wrote: Stealing Paul's answer now: ```d import std; enum your_max_length = 1000; enum your_align = 256; struct MySlice(T/*, size_t maxLength*/) { private align(your_align)T payload; //invariant(payload.length <= maxLength);

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Aug 06, 2021 at 06:02:01PM +, james.p.leblanc via Digitalmars-d-learn wrote: [...] > However, do NOT feel stupid ... the motivation behind why > I cannot use a standard int[your_max_length] (in other words, > use a static array), is because I need to do a specified > memory alignment

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread james.p.leblanc via Digitalmars-d-learn
On Friday, 6 August 2021 at 11:58:59 UTC, Paul Backus wrote: struct MySlice(T, size_t maxLength) { private T[] payload; invariant(payload.length <= maxLength); this(T[] slice) { payload = slice; } T opIndex(size_t i) { return payload[i]; } // etc. } ``` Paul, Thanks very

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 10:50:19 UTC, james.p.leblanc wrote: I am aware of the "capacity" concept with slices. But, I would like to know if it is possible to set a hard limit on a slice size. I prefer it to error and crash instead of a doing an extension or reallocation. I understand my

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 16:32:59 UTC, james.p.leblanc wrote: On Friday, 6 August 2021 at 11:58:59 UTC, Paul Backus wrote: struct MySlice(T, size_t maxLength) { private T[] payload; invariant(payload.length <= maxLength); this(T[] slice) { payload = slice; } T opIndex(size_t

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 17:16:28 UTC, Tejas wrote: On Friday, 6 August 2021 at 16:32:59 UTC, james.p.leblanc wrote: On Friday, 6 August 2021 at 11:58:59 UTC, Paul Backus wrote: [...] ``` Paul, Thanks very much for your reply. I understand only a fraction of the suggested solution. I

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread james.p.leblanc via Digitalmars-d-learn
mes On Friday, 6 August 2021 at 17:25:24 UTC, Tejas wrote: Okay we were overthinking the solution. Just use a static array ```d int[your_max_length]/*or whatever type*/ var; ``` You're good to go! I almost feel stupid now lol Hello Tejas, Kind thanks for your replies ... all are

Re: Setting a hard limit on slice size, is this possible?

2021-08-06 Thread Tejas via Digitalmars-d-learn
On Friday, 6 August 2021 at 18:02:01 UTC, james.p.leblanc wrote: mes On Friday, 6 August 2021 at 17:25:24 UTC, Tejas wrote: Okay we were overthinking the solution. Just use a static array ```d int[your_max_length]/*or whatever type*/ var; ``` You're good to go! I almost feel stupid now lol

invariants and compiler flags, best practice?

2021-08-06 Thread Bruce Carneal via Digitalmars-d-learn
I'm nervous enough about future compilations/builds of the code that I'm responsible for that I employ the following idiom quite a bit, mostly in @trusted code: (some boolean expression denoting invariants) || assert(0, "what went wrong"); How might the above cause problems and how do you