Casting to union type?

2014-08-25 Thread cc via Digitalmars-d-learn
Is it possible to allow implicit casting from a base type to a union type? For example, considering the following basic vector union: union vec2 { struct { float x = 0.0f; float y = 0.0f; } float[2] v; enum length = v.length;

Re: Casting to union type?

2014-08-26 Thread cc via Digitalmars-d-learn
Ahh, thanks. Looks like encapsulating the union in a struct with alias this gets the job done, and removes the need for overloads. Neat. struct vec2 { union { struct { float x = 0.0f; float y = 0.0f; }

Re: Strange stack variable corruption error after calling extern(C) function

2016-05-03 Thread cc via Digitalmars-d-learn
On Tuesday, 3 May 2016 at 12:48:37 UTC, Benjamin Thaut wrote: It seems that one of the fmod functions you declared is not correct. Either the fmod api is not using the c calling convention or you made a mistake when declaring the paramters of the fmod functions. You should double check that

Strange stack variable corruption error after calling extern(C) function

2016-05-03 Thread cc via Digitalmars-d-learn
Hello, I've been encountering a strange problem that seems to occur after calling some external C functions. I've been working on a program that incorporates the FMOD C API for playing sound, with a simple D binding based off the C headers, and actually everything works more or less fine,

Re: Strange stack variable corruption error after calling extern(C) function

2016-05-04 Thread cc via Digitalmars-d-learn
On Wednesday, 4 May 2016 at 09:40:55 UTC, Benjamin Thaut wrote: On Tuesday, 3 May 2016 at 19:06:30 UTC, cc wrote: it fails to link with "Error 42: Symbol Undefined _FMOD_System_CreateSound@20". With extern(C) it compiles and runs but the problem from above persists. Is this on Windows

Re: Strange stack variable corruption error after calling extern(C) function

2016-05-06 Thread cc via Digitalmars-d-learn
On Thursday, 5 May 2016 at 09:42:00 UTC, Benjamin Thaut wrote: On Wednesday, 4 May 2016 at 17:53:32 UTC, cc wrote: The OS is Win64 though the program is being compiled as 32-bit and I'm using the 32-bit distributed DLL. fmod.dll: PE32 executable (DLL) (GUI) Intel 80386, for MS Windows

Re: Getting most derived type of object that implements interface

2016-07-25 Thread cc via Digitalmars-d-learn
Ahh I see, thanks guys.

Getting most derived type of object that implements interface

2016-07-25 Thread cc via Digitalmars-d-learn
I'm having trouble getting the full name of an object of a class that implements an interface, using typeid() or .classinfo, the behavior seems to be different from that of a class that simply derives other classes. interface FooInterface {} class BarImplementsInterface : FooInterface {}

std.socket Socket.select failing on consecutive calls with listening socket

2016-07-31 Thread cc via Digitalmars-d-learn
Socket server = new TcpSocket(); server.setOption(SocketOptionLevel.SOCKET, SocketOption.REUSEADDR, true); server.bind(new InternetAddress(8000)); server.listen(8); auto set = new SocketSet(); set.add(server); auto sel = Socket.select(set,

Re: std.socket Socket.select failing on consecutive calls with listening socket

2016-07-31 Thread cc via Digitalmars-d-learn
On Sunday, 31 July 2016 at 08:29:10 UTC, ketmar wrote: On Sunday, 31 July 2016 at 08:00:02 UTC, cc wrote: socket sets usually updated after call to `select()`. you have to recreate the sets before each call. Ah that works, thanks.

Re: Strange stack variable corruption error after calling extern(C) function

2017-04-16 Thread cc via Digitalmars-d-learn
Ok, I took another stab at this since I've had the problem sitting for however many months and I think I finally got it figured out. I needed to reimport the import library from the DLL (via implib.exe) WITHOUT the /system switch, then, on inspecting it, it appears the correct function names

Re: Strange stack variable corruption error after calling extern(C) function

2017-04-16 Thread cc via Digitalmars-d-learn
All this with extern(Windows) rather than extern(C) by the way.

Re: Strange stack variable corruption error after calling extern(C) function

2017-04-16 Thread cc via Digitalmars-d-learn
On Saturday, 15 April 2017 at 00:23:42 UTC, Lewis wrote: Holy crap, thank you. I know this is late, but I was playing around with derelictFMOD, and ran into a strange crash like yours on shutdown. Looking at the disassembly revealed that FMOD_System_Close() was popping more off the stack as it

toString OutputWriter method not calling derived class

2018-05-25 Thread cc via Digitalmars-d-learn
When defining a toString(W)(ref W writer) function on a base class and derived class, only the version on the base class is called when formatting into a string. Is this intended behavior? import std.format; import std.range.primitives; class Foo { string test() {

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-10 Thread cc via Digitalmars-d-learn
On Sunday, 10 June 2018 at 02:57:34 UTC, evilrat wrote: Only subsystems getters like SteamUser() or SteamInventory() requires wrapping. I really can't understand why they ever choose to silently ignore registering callbacks received with C API systems handles... Thanks to the information

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-09 Thread cc via Digitalmars-d-learn
On Saturday, 9 June 2018 at 14:11:13 UTC, evilrat wrote: However steam devs decided to shield actual pointer and return pointer sized integer when C API is used(or they just screw up?). Anyway, the pointers for subsystems returned by context calls on C++ API and mirrored C API calls are

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-10 Thread cc via Digitalmars-d-learn
On Sunday, 10 June 2018 at 10:47:58 UTC, rikki cattermole wrote: On 10/06/2018 10:29 PM, cc wrote: And it successfully fires the 3-arg Run method of the callback object. However for some reason the function table of the ISteamClient seems to be off by one.. it kept calling the wrong methods

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
On Friday, 8 June 2018 at 02:52:10 UTC, Mike Parker wrote: On Friday, 8 June 2018 at 00:55:35 UTC, cc wrote: class CImpl : CCallbackBase { extern(C++) { If anyone has any insight to provide it would be greatly appreciated, thanks! I've not used any of the C++ interfacing features

Pass function (not alias) to template and/or delegate-ize a template argument

2018-06-11 Thread cc via Digitalmars-d-learn
Is it possible to pass a class member function as a template argument in such a way that it can 1. be called during runtime, and 2. still retrieve the UDAs of the function itself? For example, given this setup: struct MYUDA {} class Foo { @(MYUDA) int bar(int x) { return x*2; } }

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
Sample output: Initializing. User logged on: true Starting request. hid: 4838393704146785693 .. Request completed: NumberOfCurrentPlayers_t(1, 5828) Terminating. Not present: any indication that the registered callresult was executed.

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
On Saturday, 9 June 2018 at 03:07:39 UTC, cc wrote: I've put together a simplified test program here (124KB): Here is a pastebin of the D source file updated with some additional comments at the end with the callback class definitions from the original header files

Re: Passing C++ class to DLL for callbacks from D (Steam)

2018-06-08 Thread cc via Digitalmars-d-learn
On Friday, 8 June 2018 at 07:32:54 UTC, evilrat wrote: On Friday, 8 June 2018 at 06:59:51 UTC, cc wrote: On Friday, 8 June 2018 at 02:52:10 UTC, Mike Parker wrote: On Friday, 8 June 2018 at 00:55:35 UTC, cc wrote: class CImpl : CCallbackBase { extern(C++) { If anyone has any

Passing C++ class to DLL for callbacks from D (Steam)

2018-06-07 Thread cc via Digitalmars-d-learn
Hello, I'm attempting to interface with the Steam API DLL in D and running into some trouble working with callbacks. I'm aware there's already a project here http://derelict-steamworks.dub.pm/ but it seems to have not yet addressed the same issue. Steam provides ways to poll for whether an

How to get a range from std.container.array for use with std.format.sformat?

2018-01-30 Thread cc via Digitalmars-d-learn
import std.container; import std.format; Array!char str; str.length = 256; str.sformat!"%s:%s"("some", "string"); // Error: template std.format.sformat cannot deduce function from argument types !("%s:%s")(Array!char, string, string), candidates are:

Re: How to get a range from std.container.array for use with std.format.sformat?

2018-01-30 Thread cc via Digitalmars-d-learn
Still doesn't work without the cast it seems.. auto rng = str[]; rng.sformat!"%s:%s"("some", "string"); // Error: template std.format.sformat cannot deduce function from argument types !("%s:%s")(RangeT!(Array!char), string, string)

Re: Newbie: out-of-source builds with "dub"?

2018-07-30 Thread CC via Digitalmars-d-learn
On Monday, 30 July 2018 at 07:34:04 UTC, Alex wrote: I've started playing with "dub", and it *seems* to assume that you want the files generated during the build process to reside directly inside your checked-out source tree. Is that true? And if so, am I fighting dub's design by attempting

Newbie: out-of-source builds with "dub"?

2018-07-29 Thread CC via Digitalmars-d-learn
Before starting with D programming, most of my projects have configured their build systems with Autotools or CMake, and git for source control. With those systems, it's usually considered best practice to store all files generated during configuration and build to be located outside of the

Why is sformat and formattedWrite (appender) allocating GC mem here?

2019-08-31 Thread cc via Digitalmars-d-learn
And what, if anything, can I do to avoid it? string[] arr = ["abcd", "efgh", "ijkl"]; char[4096] buf; char[] res; writeln(GC.stats); res = sformat(buf, "%s", arr); assert(res.ptr == buf.ptr); writeln(res); writeln(GC.stats);

Re: Why is sformat and formattedWrite (appender) allocating GC mem here?

2019-09-01 Thread cc via Digitalmars-d-learn
On Saturday, 31 August 2019 at 21:12:32 UTC, ag0aep6g wrote: I've made a pull request to get rid of those allocations: https://github.com/dlang/phobos/pull/7163 Thanks for the responses, very cool seeing these updates happen so fluidly.

Building 64-bit Windows application with console window

2019-09-17 Thread cc via Digitalmars-d-learn
This might be more a question about the MS linker than D, but I'm noticing that when building with -m64 under DMD v2.087.1, it is no longer generating a console window when running the application. Under 32-bit, it would always generate the console window, and I had to disable it by building

Re: GC.collect inflating memory usage?

2019-12-09 Thread cc via Digitalmars-d-learn
On Sunday, 8 December 2019 at 17:49:09 UTC, Rainer Schuetze wrote: Seems like a bug introduced in dmd 2.086, I've created a bugzilla issue: https://issues.dlang.org/show_bug.cgi?id=20438 I suspect there is something broken with respect to the free-lists inside the GC when manually freeing

GC.collect inflating memory usage?

2019-12-07 Thread cc via Digitalmars-d-learn
Given the following program: //version=FREE; //version=COLLECT; import std.stdio; import std.datetime.stopwatch; import core.memory; immutable int[] intZ =

Re: Is there a std.zip.ZipArchive isDir or isFile method?

2020-02-11 Thread cc via Digitalmars-d-learn
On Monday, 3 February 2020 at 13:26:38 UTC, mark wrote: I'm using std.zip.ZipArchive to read zip files, e.g.: auto zip = new ZipArchive(read(filename)); // ... foreach (name, member; zip.directory) { if (name.endsWith('/')) // skip dirs continue;

Re: Global version/debug statements in file?

2020-02-12 Thread cc via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 09:28:15 UTC, Simen Kjærås wrote: https://dlang.org/dmd-windows.html#switches specifies that DMD may be passed a file on the command line that contains compiler arguments and switches. This may be freely combined with regular command line arguments if you so

Global version/debug statements in file?

2020-02-12 Thread cc via Digitalmars-d-learn
Is there some way to globally declare version= or debug= statements in a file and have them apply to the entire project being compiled? As the documentation says these only apply to the module scope they exist in, and need to be added to the command line otherwise. It would be a bit easier

Re: Is there a std.zip.ZipArchive isDir or isFile method?

2020-02-12 Thread cc via Digitalmars-d-learn
It looks like 004 (octal) is the flag for directories on linux, but it does seem that std.zip is explicitly returning 0 if the file was created on the opposite platform re: Posix vs Windows, which is... odd. @property @nogc nothrow uint fileAttributes() const { version (Posix) {

Should getSymbolsByUDA work with member variables?

2020-02-28 Thread cc via Digitalmars-d-learn
This compiles: class Foo { int x; @(1) void y() {} this() { static foreach (idx, field; getSymbolsByUDA!(Foo, 1)) { } } } This does not: class Foo { @(1) int x; void y() {} this() { static

Constant GC allocations when sending large messages to threads?

2020-01-29 Thread cc via Digitalmars-d-learn
Given the sample program at https://pastebin.com/u9sSNtj7 I'm experiencing GC allocations with every call to std.concurrency.send when sending larger messages (e.g. multiple ulongs). These do not occur when sending uints in comparison, in the provided example. For example, when the

Re: Constant GC allocations when sending large messages to threads?

2020-01-30 Thread cc via Digitalmars-d-learn
On Wednesday, 29 January 2020 at 21:10:53 UTC, Steven Schveighoffer wrote: I'm pretty sure std.concurrency uses Variant to pass message data, which boxes when it gets over a certain size. You are probably crossing that threshold. The allocations should level out eventually when the GC starts

format with floating points GC allocating in DMD 2.090

2020-01-30 Thread cc via Digitalmars-d-learn
char[4096] buf; writeln(GC.stats.usedSize); foreach (i; 0 .. 10) { sformat(buf, "%f", 1.234f); writeln(GC.stats.usedSize); } Output with DMD32 D Compiler v2.089.1-dirty (Win10 x64): 16 16 16 ... Output with DMD32 D Compiler

Re: Constant GC allocations when sending large messages to threads?

2020-02-02 Thread cc via Digitalmars-d-learn
On Friday, 31 January 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: You could use RefCounted to build a struct that then is sendable with the data you need. RefCounted allocates using C malloc, not the GC. Thanks for the tips. How exactly would I go about sending a RefCounted value?

Re: Get compilation errors within opDispatch?

2020-02-17 Thread cc via Digitalmars-d-learn
On Monday, 17 February 2020 at 17:01:12 UTC, Adam D. Ruppe wrote: It sometimes helps to write it out log-form foo.opDispatch!"hello"(5); should give the full error. this btw is one of the most annoying missing errors in d... This worked, thank you! On Monday, 17 February 2020 at 16:45:53

Get compilation errors within opDispatch?

2020-02-17 Thread cc via Digitalmars-d-learn
Is there any way to see the compilation errors that occurred within an opDispatch template? struct Foo { void opDispatch(string s, SA...)(SA sargs) { literally anything; } } Foo foo; foo.hello(5); Result: Error: no property `hello` for type `Foo` Desired

How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
import std.meta; enum A = AliasSeq!(1, 2, 3, 4); THREELOOP: static foreach (idx, field; A) { static if (field == 3) { pragma(msg, "Got a 3!"); break THREELOOP; } static if (idx == A.length - 1) { static assert(0, "Got no

Re: How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
Here's a more involved example of what I'm trying to accomplish. Is there an easier/cleaner way to do this? (This is still a bit reduced, what I'm actually trying to do is compare whether a given variadic typetuple passed to opDispatch is implicitly convertible to one of the parameter

Re: constructing labels for static foreach inside switch inside foreach

2020-07-08 Thread cc via Digitalmars-d-learn
On Wednesday, 8 July 2020 at 02:06:01 UTC, Steven Schveighoffer wrote: OK, so I have a situation where I'm foreaching over a compile-time list of types. Inside the loop, I'm using a second loop over a set of input. Inside that loop, I'm using a switch on the input, and inside the switch, I'm

Renamed but non-selective import?

2021-01-12 Thread cc via Digitalmars-d-learn
Is it possible to import all symbols of a module, while renaming just one of them? It seems like doing an import with renaming automatically makes it selective. In the example below, I'd prefer not to have to use the fully qualified name for mymodule.MSG every time e.g.: import

Re: Renamed but non-selective import?

2021-01-12 Thread cc via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 20:19:20 UTC, ag0aep6g wrote: On 12.01.21 21:09, cc wrote: import core.sys.windows.windows; import mymodule; // contains a struct named MSG Error: `core.sys.windows.winuser.MSG` ... conflicts with `mymodule.MSG` vs import core.sys.windows.windows : winMSG =

Re: Problem with templated alias as delegate parameter type

2021-01-12 Thread cc via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 21:32:14 UTC, Ali Çehreli wrote: On 1/12/21 12:58 PM, cc wrote: > void send(T query, void delegate(T.RESPONSE) callback) { That wants a delegate that takes a T.RESPONSE (PingResponse in this case). However, the following lambda is in fact a template: >

Problem with templated alias as delegate parameter type

2021-01-12 Thread cc via Digitalmars-d-learn
Given the following program: struct PingQuery { string msg; } struct PingResponse { string msg; } template send(T) { void send(T query, void delegate(PingResponse) callback) { writefln("Sending: %s", query); if (callback) {

Re: What exactly gets returned with extern(C) export string func() ?

2021-06-15 Thread cc via Digitalmars-d-learn
On Sunday, 13 June 2021 at 21:13:33 UTC, frame wrote: On Sunday, 13 June 2021 at 10:02:45 UTC, cc wrote: it seems to work as expected with the same C# code. Does D explicitly disallow slices as an extern(C) export parameter type? The spec says that there is no equivalent to type[]. You get

What exactly gets returned with extern(C) export string func() ?

2021-06-13 Thread cc via Digitalmars-d-learn
D under dmd/Win10/64-bit currently seems to store strings (slices) internally like so: ```d static struct DString { size_t length; immutable(char)* ptr; } static assert(DString.sizeof == string.sizeof); string s = "abcde"; DString d; memcpy(, , s.sizeof); assert(d.length ==

String "dequote" in phobos?

2021-05-13 Thread cc via Digitalmars-d-learn
Does something to dequote (unquote? or what would you call it?) a string exist in the standard library? I didn't see one in std.string, just wondering before reinventing the wheel. Something like: ```d assert(dequote(`"foo"`) == "foo"); assert(dequote(`'foo'`) == "foo");

Re: String "dequote" in phobos?

2021-05-13 Thread cc via Digitalmars-d-learn
On Thursday, 13 May 2021 at 16:40:29 UTC, Imperatorn wrote: Wouldn't this just this do that? 樂 ```d string dequote(string s) { return s[1..$-1]; } ``` The idea would be for situations where it isn't known in advance whether the string is quoted, if it is quoted properly, and whether

Re: Question about property & method access scope.

2021-05-11 Thread cc via Digitalmars-d-learn
On Tuesday, 11 May 2021 at 09:10:02 UTC, Vinod K Chandran wrote: Hi all, I am practising D with a win api GUI hobby project. I have a Window class and it resides in module window.d My WndProc function resides in another module named wnd_proc_module.d Inside my WndProc, I get the Window class

What is the difference between these template declaration forms?

2021-05-15 Thread cc via Digitalmars-d-learn
Are these identical? Or is there a different usage for the (T : something) form? ```d auto opCast(T)() if (is(T == bool)) { return _obj !is null; } ``` ```d auto opCast(T : bool)() { return _obj !is null; } ```

Re: struct destructor

2021-05-16 Thread cc via Digitalmars-d-learn
On Saturday, 15 May 2021 at 18:24:19 UTC, Alain De Vos wrote: Thanks, good idea but, It does not initiate a GC cycle or free any GC memory. Personally I wish D would re-implement "delete" and make it "just work" like one would assume, but from what I've seen there have been many many debates

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Friday, 21 May 2021 at 14:19:03 UTC, newbie wrote: Thank you, and formatValue? formattedWrite should handle this. ```d @safe struct Foo { int x = 3; void toString(W)(ref W writer) if (isOutputRange!(W, char)) { writer.formattedWrite("Foo(%s)", x); }

Re: Learning D

2021-05-14 Thread cc via Digitalmars-d-learn
On Friday, 14 May 2021 at 15:30:06 UTC, Imperatorn wrote: https://www.amazon.com/Programming-Language-Former-Python-Developers-ebook/dp/B08MD7ZB2X Anyone read it? Haven't read it, the title has me at the first five words though.

Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-06-01 Thread cc via Digitalmars-d-learn
On Tuesday, 1 June 2021 at 20:20:34 UTC, Ola Fosheim Grøstad wrote: Web components are becoming a reality, it essentially means that you have code and styling wrapped up as a component, so that you can use it by inserting a custom html-tag in your code. Given the massive amount of web

Re: How long does the context of a delegate exist?

2021-05-30 Thread cc via Digitalmars-d-learn
On Thursday, 27 May 2021 at 20:46:22 UTC, Adam D. Ruppe wrote: On Thursday, 27 May 2021 at 20:44:21 UTC, frame wrote: Did you mean to add the delegate as GC root or the data? The delegate.ptr property. Is there any way to enforce at compile time that we're not accidentally allocating when

Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-05-30 Thread cc via Digitalmars-d-learn
This is overkill for any reasonable application, but I've always wanted to design a whole UI framework in OpenGL, just for the novelty of it. I always end up having to reinvent the wheel for UI elements in my projects anyway. https://streamable.com/2uvt4h

Re: cloning array

2021-06-03 Thread cc via Digitalmars-d-learn
On Wednesday, 2 June 2021 at 17:50:13 UTC, Sean wrote: On Wednesday, 2 June 2021 at 15:32:38 UTC, Sean wrote: if so, how can I get the behavior i am searching for? Thank you. My current solution, if anyone wonders : https://github.com/patefacio/d-help/blob/master/d-help/opmix/dup.d You may

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Saturday, 22 May 2021 at 03:07:10 UTC, cc wrote: Ahh, in that case it would appear formattedWrite isn't @safe at all. Looks like you have to stick with put()? ```d @safe void toString(W)(ref W writer) if (isOutputRange!(W, char)) { //writer.formattedWrite!("FOO:%s", x); // fails

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Friday, 21 May 2021 at 16:53:48 UTC, drug wrote: 21.05.2021 18:28, cc пишет: On Friday, 21 May 2021 at 14:19:03 UTC, newbie wrote: Thank you, and formatValue? formattedWrite should handle this. ```d @safe struct Foo { int x = 3; void toString(W)(ref W writer) if

Re: Format

2021-05-21 Thread cc via Digitalmars-d-learn
On Saturday, 22 May 2021 at 03:14:35 UTC, cc wrote: Oops, disregard this. I had an error in my imports. It does in fact work in @safe. I should add as an aside then that there is an issue of errors from the body of a toString template not being displayed, and instead the template being

Re: win64 DLL stdout printing after main process completes

2021-04-26 Thread cc via Digitalmars-d-learn
On Monday, 26 April 2021 at 13:44:19 UTC, frame wrote: On Sunday, 25 April 2021 at 15:01:25 UTC, cc wrote: Adding a note in case anyone stumbles across this with a similar problem: Adding `stdout.setvbuf(0, _IONBF);` to both the main and DLL will cause D to autoflush after every write call

Re: OutOfMemoryError in D DLL appending to module-level array

2021-05-02 Thread cc via Digitalmars-d-learn
On Sunday, 2 May 2021 at 02:42:46 UTC, Adam D. Ruppe wrote: On Sunday, 2 May 2021 at 02:34:41 UTC, cc wrote: which seems to fix it, but I'm not entirely sure what's going on, if this is expected behavior, if that's the correct way to handle it, and so on. Oh I've been working on this the

OutOfMemoryError in D DLL appending to module-level array

2021-05-01 Thread cc via Digitalmars-d-learn
Ordinarily, it seems legal to append to an array that has been declared at module level (or as a static class member) that hasn't been otherwise initialized, for example: ```d class Foo {} private Foo[] cache; void main() { auto foo = new Foo(); cache ~= foo; } ``` However,

Re: OutOfMemoryError in D DLL appending to module-level array

2021-05-01 Thread cc via Digitalmars-d-learn
On Sunday, 2 May 2021 at 02:34:41 UTC, cc wrote: [...] Just to add, only appending to the array seems to give OutOfMemoryErrors. I can idup strings, call stdc malloc, etc just fine.

Re: win64 DLL stdout printing after main process completes

2021-04-25 Thread cc via Digitalmars-d-learn
On Monday, 19 April 2021 at 18:32:15 UTC, Adam D. Ruppe wrote: 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

Package import order with extern(C++) classes and std.container.array failure

2021-04-06 Thread cc via Digitalmars-d-learn
Just encountered this compilation failure in DMD winx64 2.096, which previously worked in 2.095 and prior versions. Just wondering if it's a bug, or a new issue to keep in mind when importing modules? Sorry for the complex nature of this scenario but I'll try to keep it as simple as

Re: win64 DLL stdout printing after main process completes

2021-04-19 Thread cc via Digitalmars-d-learn
On Monday, 19 April 2021 at 16:00:25 UTC, frame wrote: You miss a core.stdc.stdio import in main(). I also omit the def-File, maybe you have an error in it? It shouldn't be necessary to include. It just did: ``` dmd -m64 -ofmydll.dll -L/DLL mydll.d ``` Sorry, here's the def file, taken from

win64 DLL stdout printing after main process completes

2021-04-19 Thread cc via Digitalmars-d-learn
I'm not sure if this is something unique to D or not, but I've having a minor issue where stdout output from a DLL (either via printf or phobos std.stdio write) is not displayed until after the main process has completed. I'm making a project based around the example at

Re: win64 DLL stdout printing after main process completes

2021-04-19 Thread cc via Digitalmars-d-learn
On Monday, 19 April 2021 at 16:04:28 UTC, Mike Parker wrote: On Monday, 19 April 2021 at 14:55:03 UTC, cc wrote: And upon running, the output I receive is: ``` [Main] Start [Main] x: 5 [Main] Finished [Main] END [dll] DLL_PROCESS_ATTACH [dll] static this for mydll [dll] MyDLL_Test [dll]

Re: Can static variables in methods be local for each object?

2021-07-22 Thread cc via Digitalmars-d-learn
On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote: Is there a way to make myvar local to each instance of `X` without making it a variable of `X`? Just curious. Sorry if I missed something obvious but is there a specific reason why it isn't just a class member variable? ```d

opCast in class prevents destroy

2022-02-28 Thread cc via Digitalmars-d-learn
```d struct A {} class B { A opCast(T : A)() { return A(); } } void main() { auto b = new B(); destroy(b); } ``` fails with ``` dmd2\windows\bin\..\..\src\druntime\import\object.d(4209): Error: template instance `opCast!(void*)` does not match

Re: Printing a quoted string

2022-03-22 Thread cc via Digitalmars-d-learn
On Sunday, 20 March 2022 at 09:42:44 UTC, Caten wrote: Hi, I also need a function to "unquote" string, like this: ```d assert(unquote(`\n`)=="\n"); ``` Is there a way to do that? I rolled my own for that recently: ```d string dequote(string str) @safe pure { if (str.length < 2)

Re: Printing a quoted string

2022-03-22 Thread cc via Digitalmars-d-learn
On Tuesday, 22 March 2022 at 07:18:00 UTC, cc wrote: On Sunday, 20 March 2022 at 09:42:44 UTC, Caten wrote: Hi, I also need a function to "unquote" string, like this: ```d assert(unquote(`\n`)=="\n"); ``` Is there a way to do that? I rolled my own for that recently: ```d string dequote(string

Determining function template from runtime type: better ideas?

2022-03-22 Thread cc via Digitalmars-d-learn
Sorry for the fairly lengthy post. I'm wondering if there are any suggested good practices in place for calling templated functions using the runtime type of an object, e.g. what `typeid(object)` returns. Consider the following situation: ```d class Person { string name; int

Re: Setting struct as default parameter of a function using struct literal?

2023-09-12 Thread cc via Digitalmars-d-learn
On Monday, 11 September 2023 at 17:51:04 UTC, BoQsc wrote: I would like to set function's default struct for a function in a way that it would be visible for the reader to see what options are set. Something like `Options option = {silenceErrors: false}` If the function's defaults will

Re: Cool pattern or tragic?

2023-09-24 Thread cc via Digitalmars-d-learn
On Friday, 25 August 2023 at 21:00:08 UTC, Guillaume Piolat wrote: The idea is to deliberately mark @system functions that need special scrutiny to use, regardless of their memory-safety. Function that would typically be named `assumeXXX`. ... That way, @safe code will still need to manually

Re: Getting all struct members and values with introspection avoiding string mixins

2023-10-05 Thread cc via Digitalmars-d-learn
On Sunday, 1 May 2016 at 09:42:37 UTC, ParticlePeter wrote: I am logging arbitrary POD struct types with member names and data: void printStructInfo( T )( T info ) { foreach( i, A; typeof( T.tupleof )) { enum attribName = T.tupleof[i].stringof; writefln( "%s : %s", attribName, mixin(

Re: How to get all modules in a package at CT?

2023-10-05 Thread cc via Digitalmars-d-learn
On Thursday, 5 October 2023 at 20:42:26 UTC, mw wrote: On Thursday, 5 October 2023 at 20:07:38 UTC, user1234 wrote: No. Sorry. Generally compile time code cannot interact with the system. To be evaluable at compile time code has to be strongly pure, that is not the case of the function you

Get UDAs of self's declaration as a member?

2022-04-25 Thread cc via Digitalmars-d-learn
Hard to word this question right, but is it possible to get the UDAs assigned to a class/structure's member variable declaration, within that variable's definition? e.g. ```d import std.stdio; import std.traits; enum SPECIAL; struct Foo { void foo() { static if

Re: Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 15:23:12 UTC, Ali Çehreli wrote: auto arr = iota(10).map!(i => Foo(i.text)).array; On Monday, 25 April 2022 at 16:11:47 UTC, rassoc wrote: Foo[] arr = ["abc", "def", "ghi"].map!Foo.array; Ahh that'll do it alright, thanks

Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
```d struct Foo { string s; this(string s) { this.s = s; } } Foo foo = "a"; Foo[] foos = ["a"]; // Error: cannot implicitly convert expression `["a"]` of type `string[]` to `Foo[]` Foo[] foos = cast(Foo[]) ["a"]; // Error: e2ir: cannot cast `"a"` of type `string` to type `Foo`

Re: Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 15:00:13 UTC, Alain De Vos wrote: Not really an answer but this works, ``` void main(){ Foo foo = "a"; Foo[] foos; foos ~=foo; }% ``` Right, I can append individual elements, but can't assign or append a slice of a type that can be individually cast to the struct.

Re: Assigning to array of structs with custom constructor

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 15:13:51 UTC, Stanislav Blinov wrote: Make it explicit: ```d Foo[] foos = [Foo("a")]; ``` There's that too, but I still have to iterate manually. e.g.: ```d string[] ss = loadABunchOfStringsFromSomewhere(); //Foo[] foos = ss; //error Foo[] foos;

Re: Linked list, printing looks destructive.

2022-04-25 Thread cc via Digitalmars-d-learn
On Monday, 25 April 2022 at 01:40:01 UTC, Alain De Vod wrote: Following program is a single linked list. We expect as output 1 2 3 1 2 3 But the output is only 1 2 3 ``` If you don't need List to be treated as a true range, but just want to iterate, a simple way to do this is with opApply:

Re: Reference counting example

2022-04-26 Thread cc via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 22:16:01 UTC, cc wrote: Test application: I should point out that all this stuff with saving refcounted things to arrays and so on is extremely untested and experimental One problem I'm seeing is the inability for a refcounted class to pass itself to another

Re: A template construct like using()

2022-04-26 Thread cc via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 21:33:43 UTC, Chris Katko wrote: I swear I asked something like this before years ago but it doesn't show up in my previous forum posts. I'm looking for a construct that mimics using(var)/with(var) ```d void draw_with(bitmap* drawb, void delegate() dg) {

Re: Reference counting example

2022-04-26 Thread cc via Digitalmars-d-learn
On Tuesday, 26 April 2022 at 06:55:34 UTC, Alain De Vos wrote: Can someone provide a simple/very simple reference counting or refcounted example i can understand. Thanks. I've been playing around with the automem[1] library's RefCounted feature as we speak, it seems to fit my needs more than

Re: What are (were) the most difficult parts of D?

2022-05-17 Thread cc via Digitalmars-d-learn
On Monday, 16 May 2022 at 15:08:15 UTC, H. S. Teoh wrote: If you find yourself having to cast to/from immutable, you're using it wrong. I clearly was, which is why I'm not using it anymore. The question was "What are you stuck at? What was the most difficult features to understand? etc.", so

Re: What are (were) the most difficult parts of D?

2022-05-15 Thread cc via Digitalmars-d-learn
On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: What are you stuck at? What was the most difficult features to understand? etc. To make it more meaningful, what is your experience with other languages? Ali Immutability. Ended up having to do so many hundreds of casts to

Re: How to call destroy() in @nogc?

2022-05-24 Thread cc via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 02:55:06 UTC, Tejas wrote: On Tuesday, 24 May 2022 at 02:29:38 UTC, cc wrote: ```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; [...] FWIW your code will compile if you add `extern(C++)` to `Foo` Interesting, thanks.

How to call destroy() in @nogc?

2022-05-23 Thread cc via Digitalmars-d-learn
```d import core.memory; import core.stdc.stdlib : malloc, free; import core.lifetime : emplace; T NEW(T, Args...)(auto ref Args args) /*@nogc*/ if (is(T == class)) { enum size = __traits(classInstanceSize, T); void* mem = malloc(size); scope(failure) free(mem);

Re: How to call a function from a dll created with d ?

2022-07-07 Thread cc via Digitalmars-d-learn
On Sunday, 3 July 2022 at 09:43:20 UTC, frame wrote: app.d: ```d module app; import dimedll; import std.stdio; import std.stdio : log = writeln; pragma(lib, "dimedll.lib"); void main() { log("Lets build our own ime"); testFunc(); } ``` You should be able to change contents

getSymbolsByUDA in constructor/member functions

2022-06-15 Thread cc via Digitalmars-d-learn
```d import std.traits; class XML {} class Def { @XML { int x; int y; } int z; this() { static foreach (sym; getSymbolsByUDA!(Def, XML)) { } } } void main() { auto def = new Def; }

Re: Static struct initialization syntax behavior & it being disabled upon adding a constructor

2022-04-18 Thread cc via Digitalmars-d-learn
On Monday, 18 April 2022 at 03:21:30 UTC, H. S. Teoh wrote: Structs in D ought to be treated like "glorified ints", as Andrei puts it. If you need complex ctors and complex methods, that's a sign you should be using a class instead. Unless you're having a nice quiet get-together with friends,

  1   2   >