Re: from bytes to string

2021-11-27 Thread Coder via Digitalmars-d-learn
On Saturday, 27 November 2021 at 15:29:45 UTC, Adam D Ruppe wrote: On Saturday, 27 November 2021 at 15:24:43 UTC, Coder wrote: Question, why a function can not be nothrow if I catch in the body? Ever play Pokemon? You can't just catch the cute Bulbasaur and call it done (even thoug

Re: from bytes to string

2021-11-27 Thread Coder via Digitalmars-d-learn
On Saturday, 27 November 2021 at 13:56:46 UTC, Adam D Ruppe wrote: On Saturday, 27 November 2021 at 13:54:11 UTC, Coder wrote: My application is receiving data over a socket as immutable(ubyte)[]. How to validate them and transform them to utf8 string? What is the best way? If they&#x

from bytes to string

2021-11-27 Thread Coder via Digitalmars-d-learn
I'm lost, std.utf, std.conv, std.encoding, std.uni My application is receiving data over a socket as immutable(ubyte)[]. How to validate them and transform them to utf8 string? What is the best way? Thank you!

Re: Accurately serializing and deserializing a SysTime in binary format

2020-07-21 Thread Ecstatic Coder via Digitalmars-d-learn
On Tuesday, 21 July 2020 at 12:21:16 UTC, Steven Schveighoffer wrote: On 7/21/20 7:44 AM, Ecstatic Coder wrote: On Tuesday, 21 July 2020 at 11:01:20 UTC, drug wrote: On 7/20/20 10:04 PM, Ecstatic Coder wrote: I'm currently implementing a small open source backup tool (dub), and theref

Re: Accurately serializing and deserializing a SysTime in binary format

2020-07-21 Thread Ecstatic Coder via Digitalmars-d-learn
On Tuesday, 21 July 2020 at 11:01:20 UTC, drug wrote: On 7/20/20 10:04 PM, Ecstatic Coder wrote: I'm currently implementing a small open source backup tool (dub), and therefore I need to accurately store the file modification SysTime in binary format, so that I can later load this Sy

Re: Accurately serializing and deserializing a SysTime in binary format

2020-07-21 Thread Ecstatic Coder via Digitalmars-d-learn
As my question obviously didn't interest any expert, I took advantage of my lunch break to do some more research ;) Maybe I'm wrong, but to my knowledge, there is no function to get the number of hectonanoseconds since January 1, 1970. Fortunately I can get the number of seconds since the sam

Accurately serializing and deserializing a SysTime in binary format

2020-07-20 Thread Ecstatic Coder via Digitalmars-d-learn
I'm currently implementing a small open source backup tool (dub), and therefore I need to accurately store the file modification SysTime in binary format, so that I can later load this SysTime from the snapshot file to compare it with the current file modification SysTime. Having unfortunatel

Re: Full precision double to string conversion

2018-11-03 Thread Ecstatic Coder via Digitalmars-d-learn
On Saturday, 3 November 2018 at 18:04:07 UTC, Stanislav Blinov wrote: On Saturday, 3 November 2018 at 17:26:19 UTC, Ecstatic Coder wrote: void main() { double value = -12.000123456; int precision = 50; import std.stdio; writefln("%.*g", precision, value);

Re: Full precision double to string conversion

2018-11-03 Thread Ecstatic Coder via Digitalmars-d-learn
Actually, what I need is the D equivalent of the default ToString() function we have in Dart and C#. I don't think it means what you think it means: void main() { double value = -12.000123456; int precision = 50; import std.stdio; writefln("%.*g", precision, value); import

Re: Full precision double to string conversion

2018-11-03 Thread Ecstatic Coder via Digitalmars-d-learn
On Saturday, 3 November 2018 at 12:45:03 UTC, Danny Arends wrote: On Saturday, 3 November 2018 at 12:27:19 UTC, Ecstatic Coder wrote: import std.conv; import std.stdio; void main() { double value = -12.000123456; writeln( value.sizeof ); writeln( value ); writeln( value.to

Full precision double to string conversion

2018-11-03 Thread Ecstatic Coder via Digitalmars-d-learn
import std.conv; import std.stdio; void main() { double value = -12.000123456; writeln( value.sizeof ); writeln( value ); writeln( value.to!string() ); writeln( value.to!dstring() ); } /* 8 -12.0001 -12.0001 -12.0001 */ In Dart, value.toString() returns "-12.000123456". In C

Re: Is there a pragma or command line option to ask DMD to show a warning when it implicitly casts from long to ulong ?

2017-12-15 Thread Ecstatic Coder via Digitalmars-d-learn
On Friday, 15 December 2017 at 21:55:12 UTC, Michael wrote: On Friday, 15 December 2017 at 21:29:10 UTC, Jonathan M Davis wrote: On Friday, December 15, 2017 20:40:10 Ecstatic Coder via Digitalmars-d-learn wrote: It's taken me some time to find an implicit cast bug

Is there a pragma or command line option to ask DMD to show a warning when it implicitly casts from long to ulong ?

2017-12-15 Thread Ecstatic Coder via Digitalmars-d-learn
It's taken me some time to find an implicit cast bug ("if (my_sometimes_negative_index >= this_array.length)"), while a simple C++-like implicit-cast warning would have allowed me to find this nasty bug WAY sooner...

Re: Panda Antivirus puts the latest dmd installer in quarantine

2017-07-06 Thread Ecstatic Coder via Digitalmars-d-learn
Why is it put in quarantine? Posting the reason and some information about it would help a lot to identify the issue. If I remember well, it has detected a "W32/exploit.gen". The file was put in quarantine in the second I tried to execute the installer. Here is the current VirusTotal analysi

Panda Antivirus puts the latest dmd installer in quarantine

2017-07-06 Thread Ecstatic Coder via Digitalmars-d-learn
But no problem with any file stored inside the current .7z archive file. So I guess the problem comes from the installer executable itself. Please try to fix this as soon as possible, as this immediately drives people away from D before they even got a chance to install it...

class destructors and sub-objects

2013-08-29 Thread d coder
Greetings I have a question on class destructor method. D documentation for destructors says: "The garbage col­lec­tor is not guar­an­teed to run the de­struc­tor for all un­ref­er­enced ob­jects. Fur­ther­more, the order in which the garbage col­lec­tor calls de­struc­tors for un­ref­er­ence ob­

Re: Initializing assoc array to non-null

2013-06-01 Thread d coder
Thanks Jonathan Do you think this could make a good enhancement request? Regards - Puneet On Sat, Jun 1, 2013 at 9:34 PM, Jonathan M Davis wrote: > On Saturday, June 01, 2013 20:21:42 d coder wrote: > > Greetings > > > > Is there a way to initialize an associative arr

Initializing assoc array to non-null

2013-06-01 Thread d coder
Greetings Is there a way to initialize an associative array to a non-null (but still empty) state? The only way I know is by adding an element and then removing it. Did I miss something obvious? Basically I want to write lines 7-8 in the following code in a cleaner fashion. Any ideas? Regards - P

Re: Multi-library project path issue

2012-05-25 Thread #coder
Thanks for the quick and helpful reply. I will give it a shot. On Friday, 25 May 2012 at 06:36:07 UTC, Jacob Carlborg wrote: On 2012-05-25 08:15, #coder wrote: Hi, I am using the Mono-D for building a project with 3-4 library projects and one console project. Although I am using the Mono-D

Multi-library project path issue

2012-05-24 Thread #coder
Hi, I am using the Mono-D for building a project with 3-4 library projects and one console project. Although I am using the Mono-D but I think this issue is not unique to Mono-D. Please advise me with a solution, if I am missing something obvious here. Issue; I have two "library" project wi

Re: Frustration [Was: mysql binding/wrapper?]

2012-05-10 Thread #coder
As for mysqln, I merged jrogers patches and changed uint to size_t so it compiles on x64. You can look at it here: https://github.com/simendsjo/mysqln/tree/compile-on-recent-dmd It hasn't been tested beyond connecting to the database and fetching metadata yet. And my repository will go away ve

Re: Unable to pass shared class method as delegate

2011-04-24 Thread d coder
> > > I've copy and pasted my reply to Benjamin below, you should be able to > adapt it to your needs: > Stupid me. Should have checked the list before posting. > > The only way I've found to do this that works is using an alias - this is > probably worth a bug report if there isn't one already.

Unable to pass shared class method as delegate

2011-04-24 Thread d coder
Greetings I am facing problem passing a shared class method as an argument to a function. Look at the following minimized code snippet. class Foo { shared // compiles when commented out void bar() {} } void frop(void delegate() dg) { } void main() { shared Foo foo = new shared(Foo); f

Next Release

2011-04-20 Thread d coder
Greetings All It has been 2 months since we had release 2.052. Just wondering when is the 2.053 release planned? Also, is there an automated way to create a snapshot release from the git repositories? Regards - Puneet

Why is the struct instance being copied here?

2011-03-11 Thread d coder
Greetings Please look at the code down here. When compiled and run, I get the message "Call to postblit" printed. I think it is because of the foreach block, because the variable "i" is not declared as ref there. Is there a way to make it a ref? Regards - Puneet import std.stdio; struct Foo {

Do I need to declare instances of Mutexes, Semaphores, and Barriers shared?

2011-03-06 Thread d coder
Greetings Do I need to declare instances of Semaphores, Mutexes and Barriers shared? In most situations these objects would be naturally accessed by many threads. Regards - Puneet

Re: Why is it necessary to use synchronized functions when passing shared variables?

2011-03-05 Thread d coder
> > > It's probably complaining because using shared without synchronizing is > generally very foolish. Now, I would have _thought_ that it would still > work > without, but I apparently not. Regardless, I'm not sure why you'd want to > use > shared anything without synchronizing your access of it.

Why is it necessary to use synchronized functions when passing shared variables?

2011-03-05 Thread d coder
Greetings Why is it necessary to use synchronized functions when passing shared variables? I get error even when I am not modifying the shared variable in the function. Kindly look at the following code. I get a compile error unless I declare the functions parent and root synchronized. The compil

Re: Doubt about Synchronized Code Clocks

2011-03-01 Thread d coder
> I'm afraid that I have no idea what would be "stale" about a shared variable. > sychronized uses a mutex, and if you want to avoid race conditions, you need to > use mutexes or something similar when dealing with shared variables. But I don't > know what would be "stale" about a variable. > One

Doubt about Synchronized Code Clocks

2011-03-01 Thread d coder
Greetings I have a doubt about synchronized code blocks. I learnt that in Java the synchronized keyword has two fold effect. Firstly it locks the code to make sure that only a single thread gets access to the code block at a given time. Secondly, it makes sure that the data elements accessed insi

Re: Are function pointers compile time constants?

2011-02-20 Thread d coder
Thanks Simon.

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

Error: this for ~this needs to be type foo not type foo[1u][1u]

2011-02-13 Thread d coder
Greetings I am getting this error when I am instantiating a struct array with a single element inside another class and only if there is the destructor for the struct is explicitly defined. Is it a known error? Here is a minimized snippet that gives error: $ rdmd --main -unittest test.d Error: t

Re: Number of references to a Class Object

2011-02-13 Thread d coder
> However, it's not generally an issue, because you shouldn't normally be > keeping > references around for stuff that isn't used anymore. The garbage collector is > smart enough to deal with circular references and the like, so the biggest > cases > where you'd normally need weak references aren

Re: Number of references to a Class Object

2011-02-12 Thread d coder
> If you know roughly what to do and want to take a stab at producing a viable > patch to fix the problem, then feel free. If it's solid, it may get in. I > don't > know. It doesn't hurt to try though (as long as you're prepared for the fact > that it may not be accepted). Thanks for letting me k

Re: Number of references to a Class Object

2011-02-12 Thread d coder
> Also tango (for D 1.0) implements it. > Link: > http://www.dsource.org/projects/tango/docs/current/tango.core.WeakRef.html > > Might be worth a look if you are going to implement it for D 2.0. > I looked at the D1 implementation. It depends on GC methods weakPointerCreate and weakPointerDestroy.

Re: Number of references to a Class Object

2011-02-11 Thread d coder
> I believe what you're referring to is generally called a Weak > Reference, which is a reference that the GC doesn't consider when > deciding to keep an object alive, but that the GC will update if an > object dies. > There's a feature request at > http://d.puremagic.com/issues/show_bug.cgi?id=41

Number of references to a Class Object

2011-02-11 Thread d coder
Greetings I am in a situation where I need to know the number of references to a class' object. To explain, I have an array of class objects and I occasionally process this array. But if a particular object in this array is not being garbage collected just because it is part of this array, I would

Re: Dynamic and Static Casting

2011-02-10 Thread d coder
Thanks Lars and Bearophile, I will give it a try. I understand that static downcasting is dangerous. But there are places where efficiency is paramount and you are sure that the casting is safe. So I wholeheartedly second your proposal to have the stuff in phobos. Regards - Cherry

Dynamic and Static Casting

2011-02-10 Thread d coder
Greetings All I have learnt that D has only one casting operator and that is 'cast'. The same operator assumes different functionality depending on the context in which it he being used. Now I have a situation where I have to downcast an object and I am sure of the objects type and thereby I am s

Maximum Number of Threads?

2011-02-06 Thread d coder
Greetings Is there a limit on the maximum number of threads that can be spawned? Or does it just depend on the value in /proc/sys/kernel/threads-max on a linux system? Regards - Cherry

Re: Nested Structs

2010-12-27 Thread d coder
> A struct nested in a class does not have a hidden "outer" pointer as a > nested class does.  It's because a struct is generally more bare-bones than > a class (which has loads of hidden pieces: vtable, interfaces, classinfo, > etc.).  Also, instantiating such a struct does not tie it to a class >

Nested Structs

2010-12-27 Thread d coder
Greetings All I have a situation where I have a struct nested inside a class. I would like to make the enclosing class' members visible inside the nested struct's constructor. I see that such preposition is feasible for nested classes, but not for nested structs. Why so? Are there some alternativ

Re: is expression for template structs/classes instances?

2010-12-21 Thread d coder
> I do know the template. I will try out your solution. Will let you > know if I face issues. > Simen It works perfect, And this is exactly what I was looking for. If you see my original post, I also thought this form of "is" expression should work. Just could not get around to the right syntax.

Re: is expression for template structs/classes instances?

2010-12-21 Thread d coder
> S!int foo; > static if ( is( typeof(foo) f == S!T, T ) ) { >    // Here, T == int, f == typeof(foo) > } > > Note that the syntax "is ( Type Identifier : TypeSpecialization , > TemplateParameterList )" is only usable inside static if. > Thanks Simen I do know the template. I will try out your so

Re: is expression for template structs/classes instances?

2010-12-20 Thread d coder
> For instance, given your definiton of S, you could use > _traits/std.traits to check that the type that you're testing has a member > variable t. You could then check that S!(typeof(t)) was the same as the type > that you were testing. So, if you get particularly cunning about it, I believe > tha

is expression for template structs/classes instances?

2010-12-20 Thread d coder
Greetings I want to find if a given struct type is instantiated from a particular template struct type. For example: struct S (T) { alias T Type; T t; } And later I want to find out if a given type is of type S(*) (basically any type instantiated from template struct S). In fact I do not kn

Re: List of derived types?

2010-12-16 Thread d coder
> I'm curious, why do you need that? > It is a long story. But basically I am creating a platform wherein the users would be deriving classes from some base classes that I write as part of the platform. And the users would often be deriving many such classes. The end-users would often not be pro

List of derived types?

2010-12-16 Thread d coder
Greetings I need a way to know (using traits or other compile time constructs) all the types derived from a given type. Is it possible in D? Is it possible to get a list of all the user-defined classes? I could use that to filter out the classes that I need. Regards Cherry

Re: Facing problems with Class Properties

2010-12-10 Thread d coder
> Ah.. Now I think I understand. > > This new code I have written will all be run at compile time. So in > this case, the foreach statement inside the constructor would be > reduced to a bunch of writeln statements at compile time and those > writeln would be executed at the run time. This will not

Re: Facing problems with Class Properties

2010-12-10 Thread d coder
> Another thing, is(T : U) simply means T is implicitly castable to U.  Due to > a compiler bug, Bar[] is implicitly castable to BaseClass[]. > Steve I realize that I am using this compiler bug as a feature. It would be kind of you to suggest me a code that would not exploit this bug. I was think

Re: Facing problems with Class Properties

2010-12-10 Thread d coder
> What you are saying makes sense to me. The problem is that the > following code works perfectly. I have just commented out some part > and replaced it with some debug statements. Ah.. Now I think I understand. This new code I have written will all be run at compile time. So in this case, the fo

Re: Facing problems with Class Properties

2010-12-10 Thread d coder
> Is there a reason you can't directly reference the members?  After all, you > are writing the class. > Thanks Steve for your inputs. Actually this is part of a bigger code that I am trying to create. Though I am pretty new to D. What I have posted is a reduced code that illustrated the issue I

Re: Facing problems with Class Properties

2010-12-10 Thread d coder
> if(false) { >    for (size_t j = 0; j < f.length...) >    ... > } > > Semantically this code is wrong as you can't take the length of f which is > class Bar. The static if forces the compiler to not generate this code as it > is known to be false. > Thanks Jesse What you are saying makes sens

Facing problems with Class Properties

2010-12-10 Thread d coder
Greetings All I am trying to compile the following D2 code. The code giving compilation issues is the "this()" function of the class Foo. The constructor basically tries to initialize all the data members of the class, of type BaseClass and of type BaseClass array. I am using class property tuple