Constants?

2009-02-11 Thread Mike L.
Could someone lay out for me the different ways of doing constants in D (d1, particularly)? I've heard things about const, final, invariant, and "anonymous enums"?

Switch constants

2010-11-13 Thread bearophile
In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? template Foo(uint x) { static if (x <= 1) enum Foo = 1; else enum Foo = x * Foo!(x - 1); } i

Re: Constants?

2009-02-11 Thread Jarrett Billingsley
On Wed, Feb 11, 2009 at 4:09 PM, Mike L. wrote: > Could someone lay out for me the different ways of doing constants in D (d1, > particularly)? I've heard things about const, final, invariant, and > "anonymous enums"? > OK, D1 doesn't have constness in the wa

Re: Constants?

2009-02-11 Thread Zarathustra
PM, Mike L. wrote: > > Could someone lay out for me the different ways of doing constants in D > > (d1, particularly)? I've heard things about const, final, invariant, and > > "anonymous enums"? > > > > OK, D1 doesn't have constness in the way t

Re: Constants?

2009-02-12 Thread Mike L.
Thanks, glad to have it all in one place.

Compilation constants

2009-11-11 Thread bearophile
In a C program I have a numeric constant SIZE (that is in [1,32]), that I can define when I compile the code, like this: gcc -DSIZE=14 ... How can I do the same thing in D? The solution I have found is to put in the D code: version(B1) const SIZE = 1; version(B2) const SIZE = 2; version(B3) cons

Re: Switch constants

2010-11-13 Thread Dmitry Olshansky
On 14.11.2010 1:21, bearophile wrote: In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? Well, there is fall-through ;) And there still could be goto's. In essence "c

Re: Switch constants

2010-11-13 Thread Daniel Murphy
"bearophile" wrote in message news:ibn320$2uc...@digitalmars.com... > In a not-ranged cases body, like in the program below (that doesn't > compile), the switch variable is a compile-time constant, so why doesn't > the compile see x as constant there? In switch statements, you can do stuff lik

Re: Switch constants

2010-11-13 Thread Stanislav Blinov
bearophile wrote: In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? template Foo(uint x) { static if (x <= 1) enum Foo = 1; else enum Foo = x

Re: Switch constants

2010-11-13 Thread bearophile
Daniel Murphy: > switch(x) > { > case 0: >break; // what is x here? > case 1: >goto case 0: > } > etc You are right. Thank you for all the answers. Bye, bearophile

Re: Switch constants

2010-11-14 Thread BCS
Hello bearophile, In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? template Foo(uint x) { static if (x <= 1) enum Foo = 1; else enum Foo = x * Foo!(x - 1); } int bar(

array of constants?

2011-06-02 Thread Lloyd Dupont
I'm trying to define an array of constant like: === immutable string[int] MyDict = [ 1: "monday", 2: "tuesday", ]; And I keep having compiler error: Error1Error: non-constant expression [1:"monday",2:"tuesday"] C:\Dev\DTest\DTest1\Dexperiment\LCIDs.d9 what can I do?

Re: Compilation constants

2009-11-11 Thread Phil Deets
On Wed, 11 Nov 2009 08:50:48 -0500, bearophile wrote: In a C program I have a numeric constant SIZE (that is in [1,32]), that I can define when I compile the code, like this: gcc -DSIZE=14 ... How can I do the same thing in D? The solution I have found is to put in the D code: version(B

Re: Compilation constants

2009-11-11 Thread Phil Deets
On Wed, 11 Nov 2009 13:34:32 -0500, Phil Deets wrote: On Wed, 11 Nov 2009 13:30:17 -0500, Phil Deets wrote: On Wed, 11 Nov 2009 08:50:48 -0500, bearophile wrote: In a C program I have a numeric constant SIZE (that is in [1,32]), that I can define when I compile the code, like this:

Re: Compilation constants

2009-11-11 Thread Phil Deets
On Wed, 11 Nov 2009 13:30:17 -0500, Phil Deets wrote: On Wed, 11 Nov 2009 08:50:48 -0500, bearophile wrote: In a C program I have a numeric constant SIZE (that is in [1,32]), that I can define when I compile the code, like this: gcc -DSIZE=14 ... How can I do the same thing in D? The so

Re: Compilation constants

2009-11-11 Thread grauzone
Phil Deets wrote: On Wed, 11 Nov 2009 13:34:32 -0500, Phil Deets wrote: On Wed, 11 Nov 2009 13:30:17 -0500, Phil Deets wrote: On Wed, 11 Nov 2009 08:50:48 -0500, bearophile wrote: In a C program I have a numeric constant SIZE (that is in [1,32]), that I can define when I compile the co

Re: Compilation constants

2009-11-11 Thread Phil Deets
On Wed, 11 Nov 2009 13:45:17 -0500, grauzone wrote: You can delete your posts to emulate editing... I didn't know it was possible to delete posts from a newsgroup. How do you do that? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Re: Compilation constants

2009-11-12 Thread Chris Nicholson-Sauls
Phil Deets wrote: On Wed, 11 Nov 2009 13:45:17 -0500, grauzone wrote: You can delete your posts to emulate editing... I didn't know it was possible to delete posts from a newsgroup. How do you do that? I don't know about any other readers, but using Thunderbird just right-click the messa

Re: Compilation constants

2009-11-12 Thread Phil Deets
On Thu, 12 Nov 2009 07:17:57 -0500, Chris Nicholson-Sauls wrote: Phil Deets wrote: On Wed, 11 Nov 2009 13:45:17 -0500, grauzone wrote: You can delete your posts to emulate editing... I didn't know it was possible to delete posts from a newsgroup. How do you do that? I don't know abo

Use of GUID constants

2016-03-09 Thread KlausO via Digitalmars-d-learn
that GUID constants are declared as enums in the winapi bindings (see src\druntime\import\core\sys\windows\uuid.d). Within the dclient.d sample which comes with dmd they are explicitely defined as GUIDs: GUID IID_IHello = { 0x00421140, 0, 0, [0xC0, 0, 0, 0, 0, 0, 0, 0x46] }; So maybe they should

Checking for manifest constants

2021-03-05 Thread Bogdan via Digitalmars-d-learn
I was using a trick with dmd to check for manifest constants which worked until dmd v2.094. Yesterday I tried it on the latest compiler and it failed with: source/introspection/manifestConstant.d(37,28): Error: need this for name of type string source/introspection/type.d(156,13): Error

Constants doesn't have UDA's?

2013-06-09 Thread Temtaime
Hello guys! @("att") int t = 1; auto b = [ __traits(getAttributes, t) ]; Works. @("att") enum int t = 1; auto b = [ __traits(getAttributes, t) ]; Works also. @("att") const int t = 1; auto b = [ __traits(getAttributes, t) ]; Doesn't work. Error: first argument is not a symbol Why? Also a li

More constants in std.string?

2010-08-09 Thread simendsjo
\r and \n is used many times throughout std.string (and probably other modules like file). I assume defining constants were considered: const CR = '\r'; const LF = '\n'; So why isn't constants used instead?

Re: array of constants?

2011-06-02 Thread Etherous
You need to set it in a static constructor immutable string[int] MyDict; static this () { MyDict = cast(string[int]) [ 1: "monday", 2: "tuesday" ]; }

Re: array of constants?

2011-06-03 Thread Lloyd Dupont
thanks! "Etherous" wrote in message news:is8dbh$n22$1...@digitalmars.com... You need to set it in a static constructor immutable string[int] MyDict; static this () { MyDict = cast(string[int]) [ 1: "monday", 2: "tuesday" ]; }

documenting compile-time constants

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation.

Defining compile-time constants?

2015-09-17 Thread Tim K. via Digitalmars-d-learn
Hi! I am wondering if there is any way to define constants to pass to the compiler like in C (especially useful in combination with Makefiles, for obvious reasons), i.e.: gcc -DPREFIX=\"/usr/local\" -o myprogram main.c Like this a program can look for certain files inside

Re: Use of GUID constants

2016-03-09 Thread Ali Çehreli via Digitalmars-d-learn
On 03/09/2016 10:35 AM, KlausO wrote: > IUnknown pUnk; > > // > // Does not compile: > // > // Error: function > core.sys.windows.unknwn.IUnknown.QueryInterface(const(GUID)* riid, > void** pvObject) is not callable using argument types (const(GUID),

Re: Use of GUID constants

2016-03-10 Thread KlausO via Digitalmars-d-learn
Ok, but what's the intention behind defining GUIDs as enums in the first place ? Why not defining them as const(GUID) and let the linker sort them out ? Is there a recommended way to declare/define constants (e.g. as enums or consts) ? In C (separate compilation) they are declar

Re: Use of GUID constants

2016-03-10 Thread Mike Parker via Digitalmars-d-learn
clare/define constants (e.g. as enums or consts) ? Generally, you should use a manifest constant, e.g. enum myConst = 10; Unless you need to take the address, then you should use immutable: immutable myConst = 10; The value of a manifest constant is substituted for the symbol at the point of us

Re: Use of GUID constants

2016-03-10 Thread KlausO via Digitalmars-d-learn
ended way to declare/define constants (e.g. as enums or consts) ? Generally, you should use a manifest constant, e.g. enum myConst = 10; Unless you need to take the address, then you should use immutable: immutable myConst = 10; The value of a manifest constant is substituted for the symbol a

Re: Use of GUID constants

2016-03-10 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 10 March 2016 at 14:52:16 UTC, KlausO wrote: For GUIDs you often have to take the address (e.g. for calls to QueryInterface), so I think phobos does not correctly implement this. Yes, that was my meaning. Is the above pair (const GUID and static member) the right way to declare

Re: Use of GUID constants

2016-03-10 Thread thedeemon via Digitalmars-d-learn
On Thursday, 10 March 2016 at 15:48:14 UTC, Mike Parker wrote: Personally I would just declare one immutable value in module scope and be done with it. It really just doesn't matter. Unless you're following some sort of style guide, personal preference rules the day. I don't know if Rainers has

Re: Use of GUID constants

2016-03-11 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 9 March 2016 at 18:35:31 UTC, KlausO wrote: So maybe they should be declared as "extern GUID ..." because they also seem to be defined in windows\lib\uuid.lib which comes with DMD. Declarations come from mingw and mingw doesn't have uuid.lib: https://issues.dlang.org/show_bug.cg

Re: Use of GUID constants

2016-03-11 Thread Kagamin via Digitalmars-d-learn
Oh, it was https://github.com/D-Programming-Language/druntime/pull/1472

Re: Checking for manifest constants

2021-03-05 Thread Basile B. via Digitalmars-d-learn
On Friday, 5 March 2021 at 08:23:09 UTC, Bogdan wrote: I was using a trick with dmd to check for manifest constants which worked until dmd v2.094. Yesterday I tried it on the latest compiler and it failed with: source/introspection/manifestConstant.d(37,28): Error: need this for name of

Re: Checking for manifest constants

2021-03-05 Thread Petar via Digitalmars-d-learn
On Friday, 5 March 2021 at 08:23:09 UTC, Bogdan wrote: I was using a trick with dmd to check for manifest constants which worked until dmd v2.094. Yesterday I tried it on the latest compiler and it failed with: source/introspection/manifestConstant.d(37,28): Error: need this for name of

Re: Checking for manifest constants

2021-03-06 Thread bogdan via Digitalmars-d-learn
On Friday, 5 March 2021 at 14:42:07 UTC, Petar Kirov [ZombineDev] wrote: On Friday, 5 March 2021 at 08:23:09 UTC, Bogdan wrote: [...] I suggest this: enum globalConfig = 32; int globalValue = 22; immutable globaImmutablelValue = 22; enum isManifestConstant(alias symbol) =

Re: Constants doesn't have UDA's?

2013-06-10 Thread Jack Applegame
http://forum.dlang.org/thread/htuakrtvoyymappje...@forum.dlang.org

Re: Constants doesn't have UDA's?

2013-06-10 Thread Temtaime
Oh, i see, thanks. P.S. туй васю нигодяй.

Re: More constants in std.string?

2010-08-09 Thread Jonathan M Davis
On Monday, August 09, 2010 17:24:47 simendsjo wrote: > \r and \n is used many times throughout std.string (and probably other > modules like file). > I assume defining constants were considered: > const CR = '\r'; > const LF = '\n'; > > So why isn't

Re: More constants in std.string?

2010-08-09 Thread simendsjo
On 10.08.2010 02:46, Jonathan M Davis wrote: On Monday, August 09, 2010 17:24:47 simendsjo wrote: \r and \n is used many times throughout std.string (and probably other modules like file). I assume defining constants were considered: const CR = '\r'; const LF = '\n'; So

Re: More constants in std.string?

2010-08-09 Thread Jonathan M Davis
quot;. It's just going to replace CR with "\r" everywhere anyway. You can only do so much to save the programmer from their own stupidity and carelessness. Using constants as an attempt to reduce typos is not a good move IMHO. The language itself does try and reduce the opportuni

Re: More constants in std.string?

2010-08-09 Thread simendsjo
t's just going to replace CR with "\r" everywhere anyway. You can only do so much to save the programmer from their own stupidity and carelessness. Using constants as an attempt to reduce typos is not a good move IMHO. The language itself does try and reduce the opportunity for stupid

Re: More constants in std.string?

2010-08-09 Thread Jonathan M Davis
On Monday, August 09, 2010 18:21:21 simendsjo wrote: > Yeah, I know. I'm really just pointing out very small things here as I > try to learn the language and library. Still.. I do think that static > checking is a very good way of eliminating many common bugs. This might > have been a bad example.

Re: More constants in std.string?

2010-08-10 Thread bearophile
simendsjo: > Why a runtime error when you can have a compile time error? Because using the static type system has various kinds of costs that some people in some situations are not willing to pay. Bye, bearophile

Re: documenting compile-time constants

2015-07-06 Thread Rikki Cattermole via Digitalmars-d-learn
On 7/07/2015 1:05 p.m., Vlad Levenfeld wrote: How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation. If: /// enum MyValue = 8.2f; does not generate documentation upon its creation, please f

Re: documenting compile-time constants

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 03:30:40 UTC, Rikki Cattermole wrote: On 7/07/2015 1:05 p.m., Vlad Levenfeld wrote: How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation. If: /// enum MyValue

Re: Defining compile-time constants?

2015-09-17 Thread Rikki Cattermole via Digitalmars-d-learn
On 18/09/15 3:32 AM, Tim K. wrote: Hi! I am wondering if there is any way to define constants to pass to the compiler like in C (especially useful in combination with Makefiles, for obvious reasons), i.e.: gcc -DPREFIX=\"/usr/local\" -o myprogram main.c Like this a program ca

Re: Defining compile-time constants?

2015-09-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 17 September 2015 at 15:32:25 UTC, Tim K. wrote: I am wondering if there is any way to define constants to pass to the compiler like in C (especially useful in combination with Makefiles, for obvious reasons), i.e.: My preference is to make an app.config module that lists these

best/proper way to declare constants ?

2021-08-04 Thread someone via Digitalmars-d-learn
"; } /// next (manifest-constant): public immutable enum gstrWhatever = "..."; ``` Are manifest-constants the proper way to go ? In [http://ddili.org/ders/d.en/enum.html] Ali says: "We have discussed that it is important to avoid magic constants and instead to take advantage

How do you declare manifest constants?

2021-11-04 Thread Andrey Zherikov via Digitalmars-d-learn
I want to embed some info from build system - version info, for example. I can easily do this with C++ compiler by `-DVERSION="1.2.3"` but there is no such an option in dmd. So I'm wondering how do people workaround this? I see only one way: generate a file and add it to the build (file might b

Public constants and types in class

2020-01-27 Thread Herbert via Digitalmars-d-learn
How can a class provide it's users with named constants, enums, types, structs and not just member functions?

what is special about unittest constants

2013-02-08 Thread Dan
hat is the reason for the difference between unittest constants and module constants? Thanks, Dan

Are function pointers compile time constants?

2011-02-20 Thread d coder
Greetings I tried to initialize a struct member with a function pointer, and found that DMD2 did not like it. Are not function pointers compile time constants? And why they should not be? Regards - Cherry

Re: best/proper way to declare constants ?

2021-08-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 12:47:06AM +, someone via Digitalmars-d-learn wrote: > What are the pros/cons of the following approaches ? 1) If the constant is a POD (int, float, etc.), use: enum myValue = ...; 2) If the constant is a string or some other array: static immutable s

Re: best/proper way to declare constants ?

2021-08-04 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 01:14:26 UTC, H. S. Teoh wrote: 1) If the constant is a POD (int, float, etc.), use: enum myValue = ...; crystal-clear. 2) If the constant is a string or some other array: static immutable string myString = "..."; crystal-clear. 2) If the co

Re: best/proper way to declare constants ?

2021-08-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/4/21 9:14 PM, H. S. Teoh wrote: Unless you have a specific reason to, avoid using `enum` with string and array literals, because they will trigger a memory allocation *at every single reference to them*, which is probably not what you want. Just want to chime in and say this is NOT true fo

Re: best/proper way to declare constants ?

2021-08-04 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 02:06:13 UTC, Steven Schveighoffer wrote: On 8/4/21 9:14 PM, H. S. Teoh wrote: Unless you have a specific reason to, avoid using `enum` with string and array literals, because they will trigger a memory allocation *at every single reference to them*, which is prob

Re: best/proper way to declare constants ?

2021-08-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/4/21 10:27 PM, someone wrote: On Thursday, 5 August 2021 at 02:06:13 UTC, Steven Schveighoffer wrote: On 8/4/21 9:14 PM, H. S. Teoh wrote: Unless you have a specific reason to, avoid using `enum` with string and array literals, because they will trigger a memory allocation *at every single

Re: best/proper way to declare constants ?

2021-08-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 01:39:42AM +, someone via Digitalmars-d-learn wrote: [...] > What happens in the following case ? > > public immutable enum gudtLocations = [ >r"BUE"d : structureLocation(r"arg"d, r"Buenos Aires"d, r"ART"d), >r"GRU"d : structureLocation(r"bra"d, r"São Paulo"d, r

Re: best/proper way to declare constants ?

2021-08-04 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 02:43:09 UTC, Steven Schveighoffer wrote: The main difference between enums and static immutable is that the latter has an address at runtime. This. Gotcha. So the answer is, depends on what you are going to do with the data. There are use cases for both. If you

Re: best/proper way to declare constants ?

2021-08-04 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 03:20:17 UTC, H. S. Teoh wrote: On Thu, Aug 05, 2021 at 01:39:42AM +, someone via Digitalmars-d-learn wrote: [...] What happens in the following case ? public immutable enum gudtLocations = [ r"BUE"d : structureLocation(r"arg"d, r"Buenos Aires"d, r"ART"d),

Re: best/proper way to declare constants ?

2021-08-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/4/21 11:20 PM, H. S. Teoh wrote: On Thu, Aug 05, 2021 at 01:39:42AM +, someone via Digitalmars-d-learn wrote: [...] What happens in the following case ? public immutable enum gudtLocations = [ r"BUE"d : structureLocation(r"arg"d, r"Buenos Aires"d, r"ART"d), r"GRU"d : structureL

Re: best/proper way to declare constants ?

2021-08-05 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 10:28:00 UTC, Steven Schveighoffer wrote: H.S. Teoh, I know you know better than this ;) None of this is necessary, you just need `rtValue` for both runtime and CTFE (and compile time parameters)! Now, the original question is about *associative arrays*, which

Re: best/proper way to declare constants ?

2021-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 03:09:13PM +, someone via Digitalmars-d-learn wrote: > On Thursday, 5 August 2021 at 10:28:00 UTC, Steven Schveighoffer wrote: > > > H.S. Teoh, I know you know better than this ;) None of this is > > necessary, you just need `rtValue` for both runtime and CTFE (and > >

Re: best/proper way to declare constants ?

2021-08-05 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 15:26:33 UTC, H. S. Teoh wrote: On Thu, Aug 05, 2021 at 03:09:13PM +, someone via Digitalmars-d-learn wrote: On Thursday, 5 August 2021 at 10:28:00 UTC, Steven Schveighoffer wrote: > H.S. Teoh, I know you know better than this ;) None of this > is necessary,

Re: best/proper way to declare constants ?

2021-08-05 Thread jfondren via Digitalmars-d-learn
On Thursday, 5 August 2021 at 16:06:58 UTC, someone wrote: So if we are talking AA-arrays at compile-time only there should be nothing wrong with the following code ... right ? ... private enum pudtLocations = [ r"BUE"d : structureLocation(r"arg"d, r"Buenos Aires"d, r"ART"d), r"GRU"d :

Re: best/proper way to declare constants ?

2021-08-05 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 16:24:21 UTC, jfondren wrote: On Thursday, 5 August 2021 at 16:06:58 UTC, someone wrote: So if we are talking AA-arrays at compile-time only there should be nothing wrong with the following code ... right ? ... private enum pudtLocations = [ r"BUE"d : structure

Re: best/proper way to declare constants ?

2021-08-05 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 05, 2021 at 04:53:38PM +, someone via Digitalmars-d-learn wrote: [...] > I already assumed that loading the data from file is a goner. > > So this leaves me with two choices: > > - keep the code as it is incurring higher-than expected > compilation-time: this is solely used in a m

Re: best/proper way to declare constants ?

2021-08-05 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/5/21 11:09 AM, someone wrote: On Thursday, 5 August 2021 at 10:28:00 UTC, Steven Schveighoffer wrote: H.S. Teoh, I know you know better than this ;) None of this is necessary, you just need `rtValue` for both runtime and CTFE (and compile time parameters)! Now, the original question is

Re: best/proper way to declare constants ?

2021-08-05 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 17:12:13 UTC, H. S. Teoh wrote: [...] I'd say if the performance hit isn't noticeably bad right now, don't worry too much about it. You can always replace it later. One thing I really like about D is how easily refactorable D code tends to be. If you structure yo

Re: best/proper way to declare constants ?

2021-08-05 Thread someone via Digitalmars-d-learn
On Thursday, 5 August 2021 at 20:50:38 UTC, Steven Schveighoffer wrote: I mean eventually AAs that are reasonably available at compile time, even though the structure is determined by the runtime, should be available at compile time. This allows them to be as usable with static immutable as r

Re: best/proper way to declare constants ?

2021-08-05 Thread Ali Çehreli via Digitalmars-d-learn
On 8/5/21 5:11 PM, someone wrote: > Although I have very little experience with D, I second this: > refactoring, even huge refactors, proved to be far more straightforward > than I expected. May I humbly suggest names like Location instead of structureLocation to make refactoring even more stra

Re: best/proper way to declare constants ?

2021-08-05 Thread someone via Digitalmars-d-learn
On Friday, 6 August 2021 at 04:57:02 UTC, Ali Çehreli wrote: On 8/5/21 5:11 PM, someone wrote: > Although I have very little experience with D, I second this: > refactoring, even huge refactors, proved to be far more straightforward > than I expected. May I humbly suggest names like Location in

Re: best/proper way to declare constants ?

2021-08-05 Thread norm via Digitalmars-d-learn
On Thursday, 5 August 2021 at 01:14:26 UTC, H. S. Teoh wrote: On Thu, Aug 05, 2021 at 12:47:06AM +, someone via Digitalmars-d-learn wrote: [...] 1) If the constant is a POD (int, float, etc.), use: enum myValue = ...; 2) If the constant is a string or some other array: s

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 c

Re: How do you declare manifest constants?

2021-11-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/4/21 12:43 PM, Andrey Zherikov wrote: I want to embed some info from build system - version info, for example. I can easily do this with C++ compiler by `-DVERSION="1.2.3"` but there is no such an option in dmd. So I'm wondering how do people workaround this? I see only one way: generate

Re: How do you declare manifest constants?

2021-11-04 Thread Andrey Zherikov via Digitalmars-d-learn
de.dlang.org/packages/gen-package-version Unfortunately git/hg tags is not the only possible source of manifest constants.

Re: How do you declare manifest constants?

2021-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 04, 2021 at 05:24:44PM +, Andrey Zherikov via Digitalmars-d-learn wrote: > On Thursday, 4 November 2021 at 17:09:31 UTC, Steven Schveighoffer wrote: > > D doesn't have any equivalent for this. > > Is it possible to add this feature having `-C VERSION="1.2.3"` (`-D` > is already us

Re: How do you declare manifest constants?

2021-11-04 Thread Ali Çehreli via Digitalmars-d-learn
On 11/4/21 10:36 AM, H. S. Teoh wrote: >import __stdin : myversion; Where can we learn more of that magic? :) Ali

Re: How do you declare manifest constants?

2021-11-04 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 04, 2021 at 01:17:02PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 11/4/21 10:36 AM, H. S. Teoh wrote: > > > import __stdin : myversion; > > Where can we learn more of that magic? :) [...] I kinda cheated, because I was the one who implemented dmd's stdin feature, so

Re: Public constants and types in class

2020-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/27/20 3:05 PM, Herbert wrote: How can a class provide it's users with named constants, enums, types, structs and not just member functions? Just declare them inside the class. They then go inside the class namespace, but are not strictly part of the class instance itself. e.g.:

Re: what is special about unittest constants

2013-02-08 Thread anonymous
fined in a unittest block works with DEFINITION 1. What is the reason for the difference between unittest constants and module constants? Thanks, Dan unittest blocks are evaluated at run time, just like your DEFINITION 2, and unlike your DEFINITION 1 which would be evaluated at compile time.

Re: what is special about unittest constants

2013-02-18 Thread Lubos Pintes
Growth2013 = [ AssetReturnType.Interest : RateCurve([DateRate(Date.min, CcRate(0.007))]), ]; } However, the same constant, when defined in a unittest block works with DEFINITION 1. What is the reason for the difference between unittest constants and module constants? Thanks, Dan unittest

Re: what is special about unittest constants

2013-02-18 Thread Ali Çehreli
On 02/18/2013 08:59 AM, Lubos Pintes wrote: > Yesterday I solved similar problem by using enum. > enum GameInfo[string] games=[ > ... > ]; Be careful with that though: 'games' is a literal associative array, meaning that it will be used in the program as if it's copy-pasted in that location. It

Re: what is special about unittest constants

2013-02-18 Thread Lubos Pintes
Thank for explanation. I supposed that the enum constant is fixed and that it is also true for AA. I will convert my code before I forget. :-). Dňa 18. 2. 2013 18:22 Ali Çehreli wrote / napísal(a): On 02/18/2013 08:59 AM, Lubos Pintes wrote: > Yesterday I solved similar problem by using enum.

Re: what is special about unittest constants

2013-02-18 Thread Ali Çehreli
On 02/18/2013 09:22 AM, Ali Çehreli wrote: > static immutable GameInfo[string] games; > > static this() > { > games = [ "one" : GameInfo(1) ]; > } And to be honest, I am not sure why I define it as 'static immutable'. :) Isn't this the same thing? immutable GameInfo[string] games; static thi

Re: Are function pointers compile time constants?

2011-02-20 Thread Simon
On 20/02/2011 14:59, d coder wrote: Greetings I tried to initialize a struct member with a function pointer, and found that DMD2 did not like it. Are not function pointers compile time constants? And why they should not be? Regards - Cherry No a function doesn't have an address unti

Re: Are function pointers compile time constants?

2011-02-20 Thread d coder
Thanks Simon.

Re: Are function pointers compile time constants?

2011-02-20 Thread Nick Sabalausky
"Simon" wrote in message news:ijrdif$1nn6$1...@digitalmars.com... > On 20/02/2011 14:59, d coder wrote: >> Greetings >> >> I tried to initialize a struct member with a function pointer, and >> found that DMD2 did not like it. Are not function pointers co

Re: Are function pointers compile time constants?

2011-02-20 Thread Steven Schveighoffer
t function pointers compile time constants? And why they should not be? Regards - Cherry No a function doesn't have an address until the .exe is loaded into memory. And with Address space randomisation on 'doze there is no reasonable way to make a function pointer a compile time val

Re: Are function pointers compile time constants?

2011-02-21 Thread Simon
inter, and found that DMD2 did not like it. Are not function pointers compile time constants? And why they should not be? Regards - Cherry No a function doesn't have an address until the .exe is loaded into memory. And with Address space randomisation on 'doze there is no reasonable wa

Re: Are function pointers compile time constants?

2011-02-22 Thread Kagamin
Simon Wrote: > You could make function pointers compile time constants if: > > You disallow ASR > You disallow them when compiling to a dll > You disallow in-lining of any function of which you take the address > You disallow the linker from rearranging functions > You dis

Re: Are function pointers compile time constants?

2011-02-26 Thread Dan Olson
d coder writes: > Greetings > > I tried to initialize a struct member with a function pointer, and > found that DMD2 did not like it. Are not function pointers compile > time constants? And why they should not be? > > Regards > - Cherry I just want to point out that this

enum, immutable or const for run-time constants?

2015-01-26 Thread Nordlöw
What's the preferred way of declaring run-time constant values in D from the point of view of 1, compile-time performance 2. run-time performance 3. code-size 4. load-time 5. locality of reference module global or function global (static)

Why The D Style constants are written in camelCase?

2018-05-09 Thread BoQsc via Digitalmars-d-learn
The D Style suggest to camelCase constants, while Java naming conventions always promoted uppercase letter. Is there an explanation why D Style chose to use camelCase instead of all UPPERCASE for constants, was there any technical problem that would appear while writing in all UPPERCASE

Re: enum, immutable or const for run-time constants?

2015-01-26 Thread ketmar via Digitalmars-d-learn
On Mon, 26 Jan 2015 20:04:58 +, Nordlöw wrote: > What's the preferred way of declaring run-time constant values in D from > the point of view of > > 1, compile-time performance 2. run-time performance 3. code-size 4. > load-time 5. locality of reference module global or function global > (st

Re: Why The D Style constants are written in camelCase?

2018-05-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 09:51:37 UTC, bauss wrote: Just because. To add on to this. D is not Java, it's not C++, it's not C# etc. D is D and D has its own conventions. You're free to write your constants in all uppercase if you want. I guess if I should come up with a

Re: Why The D Style constants are written in camelCase?

2018-05-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 May 2018 at 09:38:14 UTC, BoQsc wrote: The D Style suggest to camelCase constants, while Java naming conventions always promoted uppercase letter. Is there an explanation why D Style chose to use camelCase instead of all UPPERCASE for constants, was there any technical

  1   2   >