Re: String concatenation segmentation error

2021-04-22 Thread Adam D. Ruppe via Digitalmars-d-learn
Are there any other threads in your program?

Re: win64 DLL stdout printing after main process completes

2021-04-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 19 April 2021 at 18:05:46 UTC, cc wrote: This seems to work if I flush after every printf or write in both main and the dll. I was under the impression they were supposed to share the same IO buffers though, is this not the case? Very little in D dlls right now are shared, so ther

Re: win64 DLL stdout printing after main process completes

2021-04-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 19 April 2021 at 14:55:03 UTC, cc wrote: https://wiki.dlang.org/Win32_DLLs_in_D I'm starting to think half that page should just be deleted... the version up top with the druntime dll_process_attach etc versions should really be used in all cases. And that gets even simpler too,

Re: ioctl to set mixer volume

2021-04-16 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 16 April 2021 at 17:50:13 UTC, Alain De Vos wrote: The following very simple low level C-function simply sets the mixer volume. How to convert this simple function to dlang ? ``` import core.stdc.config; import core.sys.posix.sys.ioctl; void mixer_setlevel_stereo(int mixfd,int dev,in

Re: How do I create classes dynamically?

2021-04-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 14 April 2021 at 20:38:16 UTC, Mario wrote: Maybe I am just too short in D, but I wanted to find out if it is possible to create classes dynamically. My problem is, I just don't know where to start reading. Maybe at mixin templates? What exactly do you mean? Your goal is probab

Re: Read X many bytes from File to address Y

2021-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 7 April 2021 at 12:57:12 UTC, tcak wrote: Well, I have a struct, that is defined as a variable already. I want to read X bytes from the file (not Struct.sizeof bytes though), and read into the struct variable without any extra buffer. file.rawRead((cast(ubyte*) &your_struct)[0 .

Re: Read X many bytes from File to address Y

2021-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 7 April 2021 at 11:42:56 UTC, tcak wrote: There is rawRead, but it takes an array as parameter, which causes a dirty looking code with cast etc! What did you wrote? file.rawRead(address[0 .. desiredLength]) should do what you want.

Re: Don't allow to reassign, but content is editable

2021-04-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 7 April 2021 at 12:28:25 UTC, tcak wrote: @property auto b(){ return a.ptr; } // this is a possibility, but results with overhead of calling. Also, b is not an array anymore, just int*. Why are you returning a.ptr instead of just a? If you return just a, it works fine for w

Re: Windows Console and writing Unicode characters

2021-03-30 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 08:31:02 UTC, Luhrel wrote: I have been used this trick in C++, so it might also work in D: If you follow through the link that's what I mention as being a bad idea and provide the code given as a more correct alternative. It changes a global (well to the console

Re: Why I need DUB? Will never DMD don't just use import for import packages?

2021-03-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 29 March 2021 at 19:06:33 UTC, Marcone wrote: Why can't I just use: import vibe.vibe; for import packages like Nim or Python? Why I still use DUB? I don't use dub. Just dmd -i after you set up the files in the right place. Not all libraries support that but I only use my own libra

Re: Windows Console and writing Unicode characters

2021-03-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 29 March 2021 at 02:12:57 UTC, Brad wrote: a custom implementation for writeln rather than use the one in stdout module (package?) that would mean any other functions from that package I would want to leverage I would need to include by name. You can still import std.stdio and use

Re: Cannot deduce function from argument type when single candidate

2021-03-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 29 March 2021 at 01:24:13 UTC, Preetpal wrote: writeln(isRandomAccessRange(arr)); Template arguments are passed by !(), not just (). I believe you must also pass `typeof(arr)` since isRandomAccessRange is only interested in types.

Re: How to update DUB online documentation?

2021-03-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 28 March 2021 at 17:59:49 UTC, Mark Lagodych wrote: But auto-generated online documentation and online code viewer show an outdated version (0.0.1). How to solve that? Click on the documentation page, then notice at the very bottom of the page, in small text, there's "Clear Cache".

Re: How to update terminal output?

2021-03-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 28 March 2021 at 17:13:02 UTC, Mark Lagodych wrote: Although some (all?) of that commands do not work in the Windows terminal. For instance, you can change background color ONLY using Windows API. Windows can support them all if you enable the setting. but yeah anything outside the

Re: Why Throwable.message is not a property

2021-03-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 19:32:02 UTC, uranuz wrote: Seems that a problem with concatenation is because Throwable.message has const(char)[] type, but not string. This makes some inconvenience ;-) Yes, that's what I thought. The concat operation tends to give the most flexible type of th

Re: Why Throwable.message is not a property

2021-03-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 17:46:27 UTC, uranuz wrote: Also because it is not a property in some contexts when I try to concatenate it with string without parentheses using "~" operator it fails Can you post some sample code that demonstrates this?

Re: Is there an easy way to convert a C header to a D module?

2021-03-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 March 2021 at 02:43:01 UTC, Tim wrote: Seems pretty good. Does it work on c++ stuff too? I don't think so

Re: Is there an easy way to convert a C header to a D module?

2021-03-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 March 2021 at 01:53:31 UTC, Tim wrote: I'm needing to use a c/c++ library in a D program and I'm struggling with creating a binding as it seems like an enormous amount of regex modifications. Is there an existing program that can create most if not all of a binding for me? https

Re: Workaround to "import" an exception from a DLL

2021-03-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 March 2021 at 12:27:17 UTC, evilrat wrote: The problem is that TypeInfo is not shared on Windows, which is actually roots deeper in the other problems with "sharing". Unfortunately I cannot provide you with details, but this situation is well known long standing issue. It isn't j

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 13 March 2021 at 23:41:28 UTC, David wrote: So Excel complains that it can't load my library - presumably because libphobos2 and libdruntime are not in the sandbox.ly You *might* be able to compile with --link-defaultlib-shared=false to use the static phobos+druntime... but with

Re: Two functions with different args. Taking address of the one

2021-03-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 11 March 2021 at 12:26:07 UTC, Виталий Фадеев wrote: _processMouseKey = &process; // <-- not works _processMouseMove = &process; // <-- not works This *should* actually work. What type are those variables? struct MouseKeyEvent {} struct MouseMoveEvent{} void process( ref

Re: Does is(f == function) work?

2021-03-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 11:58:45 UTC, Andrey Zherikov wrote: Should it work for in this case as well? alias f = (){}; I actually don't know. The docs do say that function pointers work differently - they match `is(typeof(f) == return)` but it isn't clear if it would match == function.

Re: How to get number of parameters in lambda?

2021-03-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 03:08:14 UTC, Paul Backus wrote: Yes, it's possible. For example: template fun(T) { It'd be nice if we could at least get the arity of a template, then perhaps speculatively instantiate it and reflect on the eponymous function then. (that's a lot of jargon lol b

Re: Does is(f == function) work?

2021-03-08 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 9 March 2021 at 02:50:11 UTC, Andrey Zherikov wrote: writeln(is(f == function));// prints "false" try is(typeof(f) == function) it is kinda weird but that's the trick

Re: D's Continous Changing

2021-03-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 5 March 2021 at 15:54:37 UTC, Paul Backus wrote: The website is *supposed* to keep documentation for old versions around, and allow you to select them using the drop-down menu at the top-right: note that in some cases my website lets you pull old versions too: http://phobos.dpldocs

Re: How can I tell if the give parameter can be run at compile time?

2021-03-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 1 March 2021 at 20:05:57 UTC, Jack wrote: int a; enum s = ""; // both return false but g(s) is expected to return true So the value must be known at compile time without any extra context. So that `a` variable might be changed somewhere else so compile time can't read or write it.

Re: Does reserve() preallocate for futher appends too?

2021-02-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 1 March 2021 at 03:07:19 UTC, Jack wrote: isn't clear for me if reserve() does preallocate memory so that that operator like arr ~= x can use previously allocate memory by reserve() or it's just used in slices like b = arr[x .. y]? Slicing never allocates memory. reserve extends the

Re: How can I make this work?

2021-02-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 28 February 2021 at 07:05:27 UTC, Jack wrote: I'm using a windows callback function where the user-defined value is passed thought a LPARAM argument type. I'd like to pass my D array then access it from that callback function. How is the casting from LPARAM to my type array done in t

Re: How can I get the variable name passed as parameter from within a function?

2021-02-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 26 February 2021 at 19:32:52 UTC, Jack wrote: I managed to do this with alias parameter in a template: this is the only way, it needs to be an alias template Also, can I short this template function somehow to syntax f!(a) omitting the g? rename g to f. If the function inside the

Re: Compile-Time Function Parameters That Aren't Types?

2021-02-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 24 February 2021 at 03:52:57 UTC, Kyle Ingraham wrote: The part that got my attention was `bool isBGR`. I was under the impression that compile-time or template parameters were only for types. No, you can pass almost anything to them. https://dlang.org/spec/template.html#templat

Re: ldc on a raspberry pi 3 running freebsd

2021-02-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 23 February 2021 at 14:56:45 UTC, Decabytes wrote: I installed it with "pkg install ldc", but embarrassingly I'm not actually sure where the compiler is. ldc isn't a recognized action on the command line It is often called `ldc2` so give that a try. btw I run gdc on my raspberry p

Re: Foo Foo = new Foo();

2021-02-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 February 2021 at 21:03:27 UTC, Jack wrote: Why doesn't this compiles? class Baa { Foo Foo = new Foo(); } Local variables inside functions are a little bit special because everything happens in sequence. This is a declaration, where there is a new namespace, but order do

Re: Foo Foo = new Foo();

2021-02-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 February 2021 at 18:15:22 UTC, JN wrote: I guess D is smart enough to figure out which is a type and which is a variable. C++ gets confused in similar situation. Well it isn't about type vs variable (except for in this exact declaration), it is just one is defined at top level an

Re: Strings and Slices

2021-02-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 18 February 2021 at 20:47:33 UTC, Mike Brown wrote: Is slices comparable to a string_view? My c++ is rusty af but yes I think so. A d slice is `struct slice { size_t length; T* ptr; }` so when in doubt just think back to what that does. string lex_identifier(ref string input)

Re: null and initialized string comparisons

2021-02-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 20:48:22 UTC, Martin wrote: is this how it supposed to be? (https://run.dlang.io/is/7B4irm) == compares contents. Both null and "" have empty contents and are interchangable for operators that work on contents. The assert just looks at the pointer, not conte

Re: Web crawler/scraping

2021-02-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 17 February 2021 at 12:12:56 UTC, Carlos Cabral wrote: I'm trying to collect some json data from a website/admin panel automatically, which is behind a login form. Does the website need javascript? If not, my dom.d may be able to help. It can download some HTML, parse it, fill i

Re: how to make this function nothrow?

2021-02-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 February 2021 at 21:04:50 UTC, Jack wrote: obviously, insert a try-catch() within catch() is a circular dependence and doesn't solve the problem either (even if it, I think it would be quite ugly) well that's prolly the way to do it, just catch Exception and like assert(0) if it

Re: Confusing with chunkBy

2021-02-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 February 2021 at 20:51:53 UTC, Maksim wrote: Thanks for answer, Adam. I lost the key word "adjacent". yeah, you aren't the only one, I think the docs should call it more more illustratively with an example or something too. The reason why it is designed this way is just to get

Re: Confusing with chunkBy

2021-02-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 15 February 2021 at 19:57:39 UTC, Maksim wrote: Hello. Why The docs say it: "chunks an input range into subranges of equivalent adjacent elements." The key word there is "adjacent". and the docs follow up "Elements in the subranges will always appear in the same order they appea

Re: How can I clean array and prevent further reallocation if there's enough space already?

2021-02-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 7 February 2021 at 21:40:12 UTC, Jack wrote: I think it would be fine except it assumes the number of items of the array to doesn't grow, it rather overwritten new elements from docs: "Use this only when it is certain there are no elements in use beyond the array in the memory bloc

Re: How can I clean array and prevent further reallocation if there's enough space already?

2021-02-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 7 February 2021 at 21:31:11 UTC, Jack wrote: assumeSafeAppend() wouldn't work in this case because I don't know the number of items that is going to be added to the array. I don't think that matters. assumeSafeAppend seems appropriate for your need.

Re: Tuple or struct as return type?

2021-02-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 6 February 2021 at 18:02:46 UTC, Martin wrote: Why/when i should prefer Tuple as a return type over returning a struct (or even string[2] in this case)? A Tuple is just a struct declared inlined. I personally use struct every single time - structs can be separately documented and

Re: Can someone explain this?

2021-02-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 6 February 2021 at 14:39:38 UTC, Jeff wrote: Okay, the above works. But, I'm not sure why? Phobos's enum conversion always looks at the identifier, whereas the rest of the language looks at the value. Remember phobos' writeln forwards to the rest of its conversions just like `to`

Re: unittest compiles w/o error though module file is not named after the module

2021-02-06 Thread Adam D. Ruppe via Digitalmars-d-learn
Module names and file names are completely independent on the language level. You can have a file `whatever.d` with `module foo.bar.totally.different;` and `import foo.bar.totally.different` and it all works as long as you add the whatever.d to the build. The only reason people recommend they

Re: Using the Standard Library with C++ Interop

2021-02-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 5 February 2021 at 21:04:00 UTC, wolfiesnotfine wrote: however sse() from core.cpuid is incorrectly reporting as false. The function properly returns true if it's not called from C++ but instead a D main function. That makes me think it is a static constructor, and indeed there is

Re: What is the difference between static linking with .a and .so libphobos?

2021-02-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 2 February 2021 at 22:39:40 UTC, WhatMeWorry wrote: Don't we want to Dynamically link with shared libphobos2.so? Yeah, I imagine what they meant was statically binding to the dynamic link library as opposed to loading certain procedures at runtime one by one. With the .a file, t

Re: How can I stop D from dropping decimals in strings

2021-02-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 2 February 2021 at 22:27:53 UTC, Tim wrote: I have to serialize an array like [0.0, 0.0, 0.0] to a Json object. During this process, the serializer creates a string of the array, but it creates "[0, 0, 0]", dropping the decimal. How can I stop this? This depends on the library you

Re: Quick question

2021-02-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 1 February 2021 at 16:19:13 UTC, Ruby The Roobster wrote: Thanks. However for a char[], .sizeof = .length because a char is one byte. Nope, char[].sizeof is a platform-specific constant not related to the length at all. void main() { import std.stdio; char[] a = "t

Re: Quick question

2021-01-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 30 January 2021 at 00:58:09 UTC, Ruby The Roobster wrote: I have question here. Is there a difference between .sizeof and .length(of a char[])? for future reference if someone stumbles on this, .sizeof is the static size of the reference, .length is the actual length of the arra

Re: Why does calling readln() more than once not work

2021-01-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 28 January 2021 at 19:25:52 UTC, Ruby The Roobster wrote: readf(" %d",&tempy); This leaves the \n at the end. A next readf thanks to the leading space would ignore that \n and keep going, but a readln stops at the first \n it sees, even if it is a leftover item in the buf

Re: Conversion error.

2021-01-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 28 January 2021 at 01:01:36 UTC, Ruby The Roobster wrote: readf("%d",x); This is why I hate readf, it is sensitive to litte things. If you put a space in that string I think it will fix it. What happens here is it reads the float, then leaves the buffer at the \n from when t

Re: Why filling AA in shared library freezes execution?

2021-01-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 27 January 2021 at 15:25:17 UTC, H. S. Teoh wrote: I'm surprised this stuff hasn't been fixed yet, considering Walter (mostly?) works on Windows. Has he never run into these issues before? It had a dconf talk spell it all out. But it can be difficult to reproduce the nasty cases

Re: Why filling AA in shared library freezes execution?

2021-01-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 27 January 2021 at 14:36:16 UTC, Adam D. Ruppe wrote: (btw as for me fixing it myself oh edit, I should point out it also requires some degree of language change to match what Microsoft's C++ does. They do dllimport and dllexport annotations to help the compiler generate the st

Re: Why filling AA in shared library freezes execution?

2021-01-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 27 January 2021 at 13:39:32 UTC, SealabJaster wrote: The biggest one for me, is that RTTI isn't "shared" across boundaries. Yeah, that's a big one. Exception handling tables are also not properly merged leading to random behavior even if you do manage to catch the exception (I w

Re: Why filling AA in shared library freezes execution?

2021-01-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 January 2021 at 21:48:10 UTC, Vitalii wrote: Q: Why filling assoc.array in shared library freeze execution? D exes loading D dlls are very broken on Windows. You can kinda make it work but there's a lot of bad design and showstopper bugs. That's the sad reality of it. I'd sugge

Re: How do I overload += operator?

2021-01-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 January 2021 at 17:09:22 UTC, Jack wrote: auto ref opAssign(string op, T)(T value) try opOpAssign instead opAssign is for = opOpAssign is for +=, -=, etc. It might be some variation but I think it works if you just rename it.

Re: real beginner question about D's web site?

2021-01-24 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 24 January 2021 at 20:05:47 UTC, WhatMeWorry wrote: mentions the $ signs, as well as the $1 and $3. See point 4 here: https://dlang.org/spec/ddoc.html#macros $(THING ...) is a macro invocation. Inside the macro definition, $0 is the full text represented by "..." here. Then $1 i

Re: Issue with socket recieve

2021-01-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 21 January 2021 at 03:24:13 UTC, Tim wrote: No, I don't. It should be all garbage collected right? Yeah, but that's where the problem comes. Note that by destructor, I mean *any* function in your code called `~this() {}`. If there are any and they call a memory allocation functi

Re: Issue with socket recieve

2021-01-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 21:31:54 UTC, Tim wrote: Unable to open 'recv.c': Unable to read file '/build/glibc-ZN95T4/glibc-2.31/sysdeps/unix/sysv/linux/recv.c' (Error: Unable to resolve non-existing file '/build/glibc-ZN95T4/glibc-2.31/sysdeps/unix/sysv/linux/recv.c'). [snip] generate a

Re: Exit code -4

2021-01-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 21 January 2021 at 00:37:19 UTC, Tim wrote: Hi all, From time to time my program crashes with exit code -4. I can't seem to find much on the code. Does anyone know what this means and how to debug the issue? Unix signal #4 is illegal instruction (negative returns usually mean i

Re: Generating documentation help

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 01:00:32 UTC, Tim wrote: But if I deleted index.html then reran the doc gen, it worked just fine. Looks like index.html is not being updated oh yeah i forgot i did that cuz I so often build individual files and it deleting the index annoyed me oop

Re: Generating documentation help

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 00:16:51 UTC, Tim wrote: They are defined "module simulator" and "module analyzer". I also have "module math" etc. that are added to the index That's weird... There are a bunch of command line args to adrdox that might help like --document-undocumented --wri

Re: Generating documentation help

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 20 January 2021 at 00:06:35 UTC, Tim wrote: Yeah, they have both. They also contain the main entrypoint What are the module names? If it is like `module foo.main;` it will be listed under `foo` as a submodule rather than top-level since it is all organized by name. (if the cod

Re: Generating documentation help

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 23:58:59 UTC, Tim wrote: The main issue is that those scripts aren't being added to index.html Do they have module definitions and doc comments in there somewhere? like here I have all kinds of things http://dpldocs.info/experimental-docs/index.html

Re: Generating documentation help

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 23:51:00 UTC, Tim wrote: I'm creating a u-services based app so my apps need to be documented properly as well. I can get around this by defining them as modules but then adrdox doesn't add them to index.html Well, it does all .d files passed in directories given

Re: What are the advantages of using betterC?

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 17:44:03 UTC, Rempas wrote: Oh ok! So there is not advantage from using it like faster compile time, better performance etc. right? The default betterC build will compile about a quarter second faster than the default normal D build, but runtime performance is a

Re: What are the advantages of using betterC?

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
betterC is a niche restricted feature set. If you don't already have a use case in mind, I'd recommend avoiding it. It is for cases where you're stuck with certain limitations to integrate with the outside world. Like running on peculiar hardware or interoperating with certain outside programs

Re: Struggling with wchar[] to string conversion

2021-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 15:32:12 UTC, Stefan wrote: contains a szExePath member that is a wchar[260]. Converting this to a string succeeds (compiler does not complain) with me32.szExePath.text You need to slice it on length. That default conversion will include all 260 chars. So yo

Re: How do I make a template function that only accepts instances of a specific class?

2021-01-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 January 2021 at 19:34:52 UTC, Jack wrote: is that sytax derived from there? sort of. it is the type pattern matching "is expression" described here: https://dlang.org/spec/expression.html#IsExpression The is(A:B) thing technically means "if A is implicitly convertible to B" w

Re: How do I enable visual styles?

2021-01-18 Thread Adam D. Ruppe via Digitalmars-d-learn
I haven't played with the pragma yet but I've done it before both with the file.exe.manifest XML file sitting alongside it and with the resource compiler before (you can use the same resource compilers for D as you use for C btw)

Re: How do I make a template function that only accepts instances of a specific class?

2021-01-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 January 2021 at 18:40:37 UTC, Jack wrote: isInstanceOf from std.traits seems to not work with class the way I need to. I'd like to make a template function accepts only class of a specified class type class A { } class B : A { } class C : A { } int f(T)(in A[int] arr) Use if(

Re: Generating documentation help

2021-01-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 17 January 2021 at 21:48:20 UTC, Paul Backus wrote: I recommend using adrdox instead: note you should be able to just dub run adrdox and it will spit out `generated_docs/files...` (assuming i haven't broken that recently)

Re: Open question: what code pattern you use usually for null safety problem

2021-01-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 14 January 2021 at 18:24:44 UTC, ddcovery wrote: This is only an open question to know what code patterns you usually use to solve this situation in D: I'm almost never in this situation except for reading things like xml or json data that may be missing. So I just special cased

Re: Developing and running D GUI app on Android

2021-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 20:23:22 UTC, H. S. Teoh wrote: Adam may be written a script for this, I'm not 100% sure. Yeah, my code does it all, though the auto-generation is more about accessing Java from D than vice versa, since implementing the D parts are simple. See the example

Re: How to debug D on Linux

2021-01-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 13 January 2021 at 13:47:55 UTC, Roguish wrote: One specific question I have is: what's the difference between -g and -debug and -d-debug? -debug enables the `debug` keyword inside the D code itself. This lets you bypass other rules temporarily. For example void foo() pure {

Re: Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 January 2021 at 13:34:16 UTC, Adam wrote: A a = new A; // I would expect this to be called for each "new B". Your expectation is wrong for D. Since that's in a `static` context, it is run at compile time. Any variable marked `static`, `__gshared`, or is struct/class/module-

Re: Associative Array Question

2020-12-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 January 2021 at 01:43:50 UTC, Chris Bare wrote: a1[10] = "testing a1"; this actually constructs a new thing since it is a straight x = y assignment. a2[10].name = "testing a2"; But this looks up something first. It doesn't construct a2[10], it

Re: Missing D files

2020-12-31 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 31 December 2020 at 15:54:58 UTC, Paul Backus wrote: The D module corresponding to the C header `string.h` is `core.stdc.string`, but it's trying to import it as `std.c.string`. It used to be std.c.* many years ago, so it is probably just an old converter. Probably an easy enough

Re: 64-bit compilation in Wine

2020-12-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 29 December 2020 at 19:39:14 UTC, Raikia wrote: So interestingly, I actually got this to work by running "sudo wine" instead of just "wine". No idea why wine needs root access on the underlying system for wine to operate properly but ok... weird. i should try that too later. Now

Re: 64-bit compilation in Wine

2020-12-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 29 December 2020 at 17:49:19 UTC, Raikia wrote: "LLVM ERROR: Could not acquire a cryptographic context: Unknown error (0x80090017) I sometimes get this too, it seems to be a bug in wine. I actually kept an old version of wine around where it works, and a new version side by side..

Re: How to resize an image ? 🤔

2020-12-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 December 2020 at 18:48:18 UTC, vnr wrote: The one given at the beginning by Adam D. Ruppe was fine with me, fyi i think I am going to move that resize code from image.d to a more independent imageresize.d or something. Same repo. Obviously won't affect you if you already using i

Re: Exchange of data through socket connection.

2020-12-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 27 December 2020 at 17:49:10 UTC, BPS wrote: void[] buff; incommingConn.receive(buff); this has no actual space to receive anything void[] buff = ['a', 's', 'd', 'f']; sock.send(buff); sock.receive(buff); and the return value needs to be ch

Re: How to resize an image ? 🤔

2020-12-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 25 December 2020 at 22:59:55 UTC, vnr wrote: tmp.data = cast(ubyte[]) myImageData; You set bytes here but an IndexedImage also needs a palette which you didn't set up. What format is your myImageData in? It might be more appropriate to set it to a TrueColorImage. IndexedImag

Re: typeid of variable of interface type holding reference to derived class

2020-12-24 Thread Adam D. Ruppe via Digitalmars-d-learn
Interfaces always give their own typeid, this is because they might point to an object that doesn't have RTTI (though the compiler SHOULD be able to figure that out statically, it doesn't try). To get the dynamic type, first cast it to Object, then type id. typeid(cast(Object) o) is typeid(Wh

Re: Can I output strings using core.stdc.stdio?

2020-12-23 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 23 December 2020 at 13:06:37 UTC, drug wrote: static foreach (ulong i; 0..args.length) { static if (is(typeof(args[i]) == string)) printf("%s\n", args[i].toStringz); static if (is(typeof(args[i]) == int)) Putting some `else` in there would help too

Re: BetterC issues with ErupteD Vulkan binding typedef handles

2020-12-20 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 20 December 2020 at 15:45:59 UTC, ParticlePeter wrote: VkSemaphore[] wait_semaphores = [], // error: TypeInfo required does it still error if you just use = null? they work the same way but might avoid the annoying error.

Re: Floating point values in structs.

2020-12-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 18 December 2020 at 16:18:12 UTC, Dave P. wrote: Is the proper solution to change the struct definition to: yeah that's the best option right now I find the setting floats to nan pretty bizarre. yeah i wrote about it here not long ago http://dpldocs.info/this-week-in-d/Blog.Post

Re: Hex constant method starts from ".a": 0xCCCCCC.argb

2020-12-14 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 14 December 2020 at 16:11:16 UTC, Jacob Carlborg wrote: Or you can call it `rgba`. It seems to be what Wikipedia prefers [1]. The ordering here tends to reflect the bytes. So argb puts the alpha byte first in the array whereas rgba puts red first. But there's other ways here inclu

Re: Using multiple mixin templates to implement operator overloading

2020-12-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 12 December 2020 at 20:26:00 UTC, Dennis wrote: If issue 19365 got fixed eeek I thought that was fixed but apparently not :( so yeah alias won't work for operator overloads. Does work for other functions so good technique to know but not here. So for op prolly go with the strin

Re: Using multiple mixin templates to implement operator overloading

2020-12-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 12 December 2020 at 18:14:31 UTC, Paul Backus wrote: IMO this is one of the stupider design decisions in D, but it's unlikely it will ever be fixed. It is useful in several other contexts though, including user overriding and private data stores for the mixin. The easiest workar

Re: SIGUSR1, SIGUSR2

2020-12-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 11 December 2020 at 17:29:12 UTC, Panke wrote: But somehow my process gets signalled with USR1 and USR2 all the time. If I do The garbage collector uses sig usr1/2 to pause threads so it can do its collection work. When debugging just ignore them. My .gdbinit has these lines: han

Re: read till EOF from stdin

2020-12-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 11 December 2020 at 16:37:42 UTC, kdevel wrote: expected: program ends found: program still reading works for me looks like i have libc-2.30.so so i guess i have the fixed libc. Can you confirm what version you have? I did `ls /lib/libc*` to pick that out but it might be diff

Re: How to make Create Window Work?

2020-12-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:45:18 UTC, Ruby The Roobster wrote: 0, // window menu here, that's the only int you do and I'm pretty sure that's supposed a be a HMENU which is a HANDLE, which is a void* rather than an int. C will cast 0 to null

Re: How to make Create Window Work?

2020-12-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:37:16 UTC, Ruby The Roobster wrote: It's not the 'NULL' that's the error. I know. It doesn't compile because of the '0' . That is what I need to fix, since I want to make a WM_COMMAND for that button. Use lowercase `null` instead.

Re: How to make Create Window Work?

2020-12-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 9 December 2020 at 17:25:10 UTC, Ruby The Roobster wrote: CreateWindow("BUTTON".toUTF16z, // window class name fyi for a string literal like this you can just do "BUTTON"w.ptr // note the w This gives an error saying: Cannot pas argument of type 'int' to argum

Re: type suffix for character literal

2020-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 7 December 2020 at 22:26:52 UTC, Ben Jones wrote: Are there suffices (suffixes?) for character literals? nope. Is there a more succinct of writing "the literal 'x' as a dchar" than dchar('x')? You should rarely need to since there's implicit casting. but I think that is the best

Re: Static on free functions

2020-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 7 December 2020 at 17:01:45 UTC, Dave P. wrote: Does `static` on a free function definition do anything? Nope, D allows a lot of useless attributes so it doesn't complain if you do certain things out of habit (or it is just a lazy implementation, I'm not sure which explanation appl

Re: Request assistance initializing struct instance at global scope

2020-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 7 December 2020 at 04:13:16 UTC, Andrew Edwards wrote: Given: === extern(C): char*[] hldr; Why is this extern(C)? A D array ere is probably wrong. In C, a `char*[] hldr = {...}` is actually represented in D as a static length array, like `char*[1] = [null];` It shoul

Re: Is core.thread.osthread.Thread thread-safe?

2020-12-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 5 December 2020 at 18:48:19 UTC, tsbockman wrote: (The documentation for core.thread is broken right now, with dead links and at least one reference to an example that doesn't actually appear anywhere on the page.) im not sure about your other question but use my docs they actual

Re: ParameterIdentifierTuple returns empty strings

2020-12-02 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 2 December 2020 at 11:46:26 UTC, Andre Pany wrote: alias fpt = extern(C) nothrow void function(int a, int b); Function pointers don't really have parameter names. They are allowed for user habit and documentation purposes, but the compiler mostly* ignores them; they aren't actua

<    1   2   3   4   5   6   7   8   9   10   >