www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Pre-import version statements

reply Chris Piker <chris hoopjump.com> writes:
Hi D

In my C code I used to typically put the line:
```
#define _POSIX_C_SOURCE 200112L
```
in the source before importing any standard library headers.  Is 
there something equivalent for phobos?  Say 
`version(phobos2.100)` or similar?

I don't particularly need this functionality, just checking to 
see if there as a formal way to denote what library standard the 
application code is expect to work against.

Thanks,
Jul 19 2023
parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Wednesday, July 19, 2023 10:56:26 PM MDT Chris Piker via Digitalmars-d-
learn wrote:
 Hi D

 In my C code I used to typically put the line:
 ```
 #define _POSIX_C_SOURCE 200112L
 ```
 in the source before importing any standard library headers.  Is
 there something equivalent for phobos?  Say
 `version(phobos2.100)` or similar?

 I don't particularly need this functionality, just checking to
 see if there as a formal way to denote what library standard the
 application code is expect to work against.

 Thanks,
D has nothing equivalent to that. You compile your code with whichever version of dmd (or ldc, gdc, etc.) that you want, and it either compiles or it doesn't. The features of the compiler and the standard library go hand in hand, and you can't do something like use dmd version X while saying that you want Phobos version Y. They're both going to be the same version. The compiler may have additional switches to turn features on and off (e.g. to enable checks for functionality that's being added as part of a DIP but isn't the default behavior yet), but the compiler and standard library are versioned together. The closest thing to what you're talking about that I can think of in D would be __VERSION__, which simply gives you access to the version of the compiler that you're compiling with. So, it's compiler-specific, and all it gives you is an integer value. As such, outside of very rare cases, it would likely be a bad idea to actually use it for any form of conditional compilation. https://dlang.org/spec/lex.html#specialtokens Typically, the approach that people use it to just always use the latest compiler. And outside of deprecations being removed or bad luck with bug fixes, code usually just continues to work. And if they need to stick to an older version of the compiler for some reason, they just use that version of the compiler. But writing code that explicitly depends on a particular version of the compiler is not something that many projects are likely to be doing. - Jonathan M Davis
Jul 19 2023
parent reply Chris Piker <chris hoopjump.com> writes:
On Thursday, 20 July 2023 at 06:44:30 UTC, Jonathan M Davis wrote:

 D has nothing equivalent to that. You compile your code with 
 whichever version of dmd (or ldc, gdc, etc.) that you want, and 
 it either compiles or it doesn't.
Thanks :) As I developer that doesn't bother me too much, though I can imagine that management would be concerned. For larger projects it's appreciated when I can point to a particular fixed standard that I'm following. In addition to the `#define` statement above, my libraries were also compiled with `gcc -std=c99`. I'll move over to a compiler specific area and broach the topic.
Jul 20 2023
parent bachmeier <no spam.net> writes:
On Thursday, 20 July 2023 at 15:45:04 UTC, Chris Piker wrote:
 On Thursday, 20 July 2023 at 06:44:30 UTC, Jonathan M Davis 
 wrote:

 D has nothing equivalent to that. You compile your code with 
 whichever version of dmd (or ldc, gdc, etc.) that you want, 
 and it either compiles or it doesn't.
Thanks :) As I developer that doesn't bother me too much, though I can imagine that management would be concerned. For larger projects it's appreciated when I can point to a particular fixed standard that I'm following. In addition to the `#define` statement above, my libraries were also compiled with `gcc -std=c99`. I'll move over to a compiler specific area and broach the topic.
This is one of the arguments for a LTS release. If you know you can compile your code for, say, the next four years, including dependencies, it's not likely to be a problem. If there's a new compiler released eight times a year, there's no hope for that kind of stability, particularly when there are any dependencies.
Jul 20 2023