Re: #define-like behavior

2023-03-13 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 05:47:35 UTC, Jeremy wrote: Hi, in C and C++ you can use #define to substitute a value in place of an identifier while preprocessing. If you initialize a new string and don't change its value after that, will the compiler substitute the string identifier with its va

Re: #define-like behavior

2023-03-13 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 14 March 2023 at 05:47:35 UTC, Jeremy wrote: Hi, in C and C++ you can use #define to substitute a value in place of an identifier while preprocessing. If you initialize a new string and don't change its value after that, will the compiler substitute the string identifier with its va

#define-like behavior

2023-03-13 Thread Jeremy via Digitalmars-d-learn
Hi, in C and C++ you can use #define to substitute a value in place of an identifier while preprocessing. If you initialize a new string and don't change its value after that, will the compiler substitute the string identifier with its value, like #define in C, or will it make a string in memor

DMD: what's the proper way to get a list of symbols from a Module object?

2023-03-13 Thread ryuukk_ via Digitalmars-d-learn
Hello, I am playing a little bit with DMD to get familiar with it (just to get a basic overview of it) I'm trying to come up with a proof of concept for https://github.com/dlang/DIPs/blob/master/DIPs/DIP1044.md ```D enum Tester { KNOWN = 1, WITHAUTO = 2 } void func(Tester a, Tester

Re: Best way to read/write Chinese (GBK/GB18030) files?

2023-03-13 Thread zjh via Digitalmars-d-learn
On Monday, 13 March 2023 at 15:50:37 UTC, Steven Schveighoffer wrote: What is required is an addition to the `std.encoding` module, to allow such an encoding. Thank you for your information.

Re: Directly compiling a D program with other libraries

2023-03-13 Thread Jeremy via Digitalmars-d-learn
That's a linker error, meaning the missing symbol isn't available to link into the executable. You need to compile the source of all the libraries you use and make sure the resultant binaries are available for the linker to link into the executable. The -I switch you've passed tells the compi

Re: Preventing the Compiler from Optimizing Away Benchmarks

2023-03-13 Thread jmh530 via Digitalmars-d-learn
On Monday, 13 March 2023 at 15:23:25 UTC, user1234 wrote: [snip] [1] https://theunixzoo.co.uk/blog/2021-10-14-preventing-optimisations.html that's illegal code. You mix GCC/LLVM syntax with D asm block and the front-end wont recognize that. LDC recognizes a syntax similar to what is descr

Re: const in functions

2023-03-13 Thread Basile B. via Digitalmars-d-learn
On Sunday, 12 March 2023 at 15:09:45 UTC, Salih Dincer wrote: Hi, [...] // A, we can get its to guarantee us that parameters // won't change: auto inConst(T)(T a, const T b) // const { // it's not needed --^ but ^-- why can't this be used Well you got the great answers to your questio

Re: Best way to read/write Chinese (GBK/GB18030) files?

2023-03-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/12/23 8:32 PM, zjh wrote: On Sunday, 12 March 2023 at 20:03:23 UTC, 0xEAB wrote: ... Thank you for your reply, but is there any way to output `gbk` code to the console? What is required is an addition to the `std.encoding` module, to allow such an encoding. Encodings are simply tr

Re: const in functions

2023-03-13 Thread Ali Çehreli via Digitalmars-d-learn
On 3/13/23 08:17, Salih Dincer wrote: > In this case, using `ref` will increase performance while reducing the > number of copies. I am not sure about that. Unless there is an expensive copy construction, most objects are simple data copies. To use 'ref' or not should be guided through semant

Re: Preventing the Compiler from Optimizing Away Benchmarks

2023-03-13 Thread user1234 via Digitalmars-d-learn
On Monday, 13 March 2023 at 14:17:57 UTC, jmh530 wrote: I was looking at [1] for ways to prevent the compiler from optimizing away code when trying to benchmark. It has the following C++ code as a simpler version: ``` inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { asm volati

Re: const in functions

2023-03-13 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 12 March 2023 at 19:09:13 UTC, Ali Çehreli wrote: --- In this case, using `ref` will increase performance while reducing the number of copies. Would it be wise to use `const ref` to protect the routine from ourselves or someone else? For example: ```d auto inConst( //const

Re: Code organization, dub, etc.

2023-03-13 Thread Joe via Digitalmars-d-learn
On Monday, 13 March 2023 at 13:58:29 UTC, Adam D Ruppe wrote: I'm not particularly interested in defending dub - i consider it a useless piece of crap that I only suffer through cuz some users demanded it For the record, I wasn't trying to attack dub (or dfmt). I was more interested in deter

Preventing the Compiler from Optimizing Away Benchmarks

2023-03-13 Thread jmh530 via Digitalmars-d-learn
I was looking at [1] for ways to prevent the compiler from optimizing away code when trying to benchmark. It has the following C++ code as a simpler version: ``` inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp& value) { asm volatile("" : "+r,m"(value) : : "memory"); } ``` I made an att

Re: Code organization, dub, etc.

2023-03-13 Thread Joe via Digitalmars-d-learn
On Monday, 13 March 2023 at 13:32:04 UTC, Mike Parker wrote: The package registry is full of libraries, yes. That's what it's primarily for. There aren't a lot of executables uploaded there because they're usually better distributed in other ways. But plenty of people are using dub to build the

Re: Code organization, dub, etc.

2023-03-13 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 13 March 2023 at 13:20:21 UTC, Joe wrote: Yeah, it seems like it's *only* for libraries (and a few single-exe utilities). Looking at code.dlang.org, under "Stand-alone applications/Server software", the top rated item is "handy-httpd" which according to its dub.json builds a librar

Re: Code organization, dub, etc.

2023-03-13 Thread Mike Parker via Digitalmars-d-learn
On Monday, 13 March 2023 at 13:20:21 UTC, Joe wrote: Yeah, it seems like it's *only* for libraries (and a few single-exe utilities). Looking at code.dlang.org, under "Stand-alone applications/Server software", the top rated item is "handy-httpd" which according to its dub.json builds a libra

Re: Code organization, dub, etc.

2023-03-13 Thread Joe via Digitalmars-d-learn
On Monday, 13 March 2023 at 12:56:57 UTC, Bradley Chatha wrote: For better or for worse we're stuck with dub as the standard package manager + build tool one-in-all for most of our open source libraries. Yeah, it seems like it's *only* for libraries (and a few single-exe utilities). Looking

Re: Code organization, dub, etc.

2023-03-13 Thread Bradley Chatha via Digitalmars-d-learn
On Monday, 13 March 2023 at 10:52:11 UTC, Joe wrote: months. Am I missing something on how to deal with multi-executable projects in dub (and I can think of many such projects)? Dub isn't very good at doing more than relatively basic things natively (which covers enough D projects for it to

Re: Directly compiling a D program with other libraries

2023-03-13 Thread Mike Parker via Digitalmars-d-learn
On Monday, 13 March 2023 at 05:05:27 UTC, Jeremy wrote: Hello, I am new to this forum and to D. I am trying to compile a basic D program with libraries (`requests` which requires `cachetools` and `automem`) without using dub. I have never used dub before, only a compiler. The folders contain