Templated class requires values even though having default value

2021-05-09 Thread tcak via Digitalmars-d-learn
public class OpenCLKernel(size_t dim = 1) if( (dim >= 1) && (dim <= 3) ) { public this( OpenCLProgram program, in string kernelName ) { // ... } } I have a class definition as above. When I want to create

Re: String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
On Friday, 23 April 2021 at 00:30:02 UTC, Adam D. Ruppe wrote: On Thursday, 22 April 2021 at 21:15:48 UTC, tcak wrote: "positions" array is defined as auto positions = new float[ 100 ]; So, I am 100% sure, it is not out of range. "ri*dim + 1" is not a big number at all. Oh and *where* is

Re: String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
In other parts of the code, concatenation operations are all failing with same error. I need guidance to get out of this situation. My assumption was that as long as there is empty heap memory, concatenation operation would succeed always. But, it doesn't seem like so.

String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
string fileContent = ""; ... writeln(ri, ": debug 1"); foreach(i; 0..dim) { if( i > 0 ){ fileContent ~= "\t"; } writeln(ri, ": debug 1.1: ", ri*dim + i, ": ", positions[ ri*dim + i ]); fileContent ~= to!string(positions[ ri*dim + i ]); writeln(ri, ": debug 1.2: ", ri*dim

Re: Read X many bytes from File to address Y

2021-04-07 Thread tcak via Digitalmars-d-learn
On Wednesday, 7 April 2021 at 12:50:01 UTC, Adam D. Ruppe wrote: 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])

Don't allow to reassign, but content is editable

2021-04-07 Thread tcak via Digitalmars-d-learn
In javascript, with "const" keyword, you assign an object to a variable. Later, you cannot assign anything else to that variable, but content of it still can be changed. No matter by using "immutable" or "const", I cannot imitate that. Is there a way to do this without an overhead (like

Read X many bytes from File to address Y

2021-04-07 Thread tcak via Digitalmars-d-learn
I am talking about std.file.File. I have opened the file, and at a specific offset. I want to read X many bytes from the file, and want it to be written to given address directly without any Magical D-stuff like ranges etc. Is there a way to do this without getting into C or Posix header

Include http based module

2021-02-19 Thread tcak via Digitalmars-d-learn
I have written a test module and put it into /var/www/html: module mymodule; import std.stdio; void testMe(){ writeln("I tested you!"); } Then I have a main file where I would like to call the function "testMe". My build line is as follows: dmd main.d "http://localhost/mymodule.d;

New with alias

2020-03-10 Thread tcak via Digitalmars-d-learn
I write a code as below: auto result = new char[4]; It allocates memory as expected. Later I define an alias and do the above step: alias Pattern = char[4]; auto result = new Pattern; But compiler says: Error: new can only create structs, dynamic arrays or class objects, not `char[4]`'s

Re: Alias of template class

2019-11-30 Thread tcak via Digitalmars-d-learn
On Saturday, 30 November 2019 at 09:39:59 UTC, tcak wrote: I defined a class: class KNN(size_t k){} I want to define an alias for KNN when k=5, alias KNN5 = KNN!5; So that I could define a variable as KNN5 knnObject; Then create it later as knnObject = new KNN5(); But the compiler

Alias of template class

2019-11-30 Thread tcak via Digitalmars-d-learn
I defined a class: class KNN(size_t k){} I want to define an alias for KNN when k=5, alias KNN5 = KNN!5; So that I could define a variable as KNN5 knnObject; Then create it later as knnObject = new KNN5(); But the compiler gives error for the alias line: Error: template instance

Re: String Comparison Operator

2017-04-30 Thread tcak via Digitalmars-d-learn
On Sunday, 30 April 2017 at 15:31:39 UTC, Jolly James wrote: Is there a String Comparison Operator in D? You normally use double equation marks (==) to do that. auto name = "Jack"; if( name == "Jack" ) writeln("Hi Jack!");

Get list of public methods of struct

2017-03-09 Thread tcak via Digitalmars-d-learn
Is there any way to get list of public methods of a struct? I looked at both "traits" and "std.traits". getVirtualFunctions and getVirtualMethods are closest I guess, but they don't seem like general purpose due to "Virtual" part. (Wouldn't it work if a method was final?) I saw

Re: Referring to array element by descriptive name

2017-01-14 Thread tcak via Digitalmars-d-learn
On Saturday, 14 January 2017 at 15:11:40 UTC, albert-j wrote: Is it possible to refer to an array element by a descriptive name, just for code clarity, without performance overhead? E.g. void aFunction(double[] arr) { double importantElement = arr[3]; ... use importantElement ... }

Creating shared library on Monodevelop with MonoD, Implib problem

2016-11-18 Thread tcak via Digitalmars-d-learn
I am on Ubuntu. I try to create a very basic (one empty function declaration) shared library for testing. MonoD (version 2.14.5), generates a command line similar to following: dmd -debug -gc "myclass.d" "-I/usr/include/dmd" "-L/IMPLIB:/home/user/Projects/Router/bin/Debug/libRouter.a"

Re: Real Simple Question?

2016-10-25 Thread tcak via Digitalmars-d-learn
On Saturday, 22 October 2016 at 21:34:36 UTC, WhatMeWorry wrote: On Saturday, 22 October 2016 at 20:51:14 UTC, Jonathan M Davis wrote: [...] Ok, but now I'm getting these error in my new mypackage/constants.d ..\common\vertex_data.d(5,15): Error: undefined identifier 'GLfloat'

Posix access function

2016-10-18 Thread tcak via Digitalmars-d-learn
Checked std.stdio, std.file, std.path, couldn't have found anyway to check permissions on a file for read, write, execute. Without getting into core module, does it exist anywhere in std module?

Re: Programming in D by Ali Çehreli

2016-10-17 Thread tcak via Digitalmars-d-learn
On Monday, 17 October 2016 at 18:20:00 UTC, cym13 wrote: On Monday, 17 October 2016 at 18:10:01 UTC, vino wrote: [...] I don't see what you don't understand, you said it yourself: "neither the slice nor its elements can be modified". So you can't modify the elements of an immutable array.

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-17 Thread tcak via Digitalmars-d-learn
On Sunday, 16 October 2016 at 22:36:15 UTC, Nordlöw wrote: On Sunday, 16 October 2016 at 22:00:48 UTC, Nordlöw wrote: Which flag(s) in `src/posix.mak` did you change? Does make -f posix.mak MODEL_FLAG=-fPIC work? I'm sitting on a 16.04 system right now (which I don't dare to upgrade

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-16 Thread tcak via Digitalmars-d-learn
On Sunday, 16 October 2016 at 17:42:44 UTC, tcak wrote: On Thursday, 13 October 2016 at 17:02:32 UTC, Nordlöw wrote: [...] I have upgraded my Ubuntu to 16.10 yesterday as well, and I am getting following error: /usr/bin/ld: obj/Debug/program.o: relocation R_X86_64_32 against symbol

Re: Speed of synchronized

2016-10-16 Thread tcak via Digitalmars-d-learn
On Sunday, 16 October 2016 at 08:41:26 UTC, Christian Köstlin wrote: Hi, for an exercise I had to implement a thread safe counter. This is what I came up with: [...] Could you try that: class ThreadSafe3Counter: Counter{ private long counter; private core.sync.mutex.Mutex mtx;

Re: Cannot link with libphobos2.a with GCC 6.2 on Ubuntu 16.10

2016-10-16 Thread tcak via Digitalmars-d-learn
On Thursday, 13 October 2016 at 17:02:32 UTC, Nordlöw wrote: I just upgraded my Ubuntu to 16.10 and now my rebuilding of dmd from git master fails as /usr/bin/ld: idgen.o: relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not be used when making a shared object; recompile with

Re: Anonymous class

2016-10-12 Thread tcak via Digitalmars-d-learn
On Wednesday, 12 October 2016 at 11:56:21 UTC, tcak wrote: I feel like I remember that this was added to D a while ago, but I am not sure. Is it possible to create anonymous classes? public interface Runnable{ void run(); } runIt( new Runnable(){ void run(){ /* do stuff */

Anonymous class

2016-10-12 Thread tcak via Digitalmars-d-learn
I feel like I remember that this was added to D a while ago, but I am not sure. Is it possible to create anonymous classes? public interface Runnable{ void run(); } runIt( new Runnable(){ void run(){ /* do stuff */ } }); I want to do this without making the things any

Re: Module Clarification

2016-09-21 Thread tcak via Digitalmars-d-learn
On Wednesday, 21 September 2016 at 14:17:56 UTC, Jonathan Marler wrote: I'm working on a code generation tool and wanted to make sure my module approach was correct. The generated code has a module hierarchy, where modules can appear at any level of the hierarchy. module foo; module

Re: Program locked at joinAll and sched_yield

2016-07-03 Thread tcak via Digitalmars-d-learn
On Sunday, 3 July 2016 at 17:19:04 UTC, Lodovico Giaretta wrote: On Friday, 1 July 2016 at 12:02:11 UTC, tcak wrote: I have my own Http Server. Every request is handled by a thread, and threads are reused. I send 35,000 request (7 different terminals are sending 5000 requests each) to the

Re: shared Mutex?

2016-06-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 June 2016 at 18:31:16 UTC, cy wrote: I was thinking of using threads in a D program (ignores unearthly wailing) and I need 1 thread for each unique string resource (database connection info). So I did this: shared BackgroundDB[string] back; I don't see any way to make less

Base64 of String without casting

2016-06-01 Thread tcak via Digitalmars-d-learn
I understand that Base64 uses Ranges, and since String is seen and used as unicode by Ranges (please tell me if I am wrong). I am guessing, for this reason, auto btoa = std.base64.Base64.encode("Blah"); doesn't work. You need to be casting the string to ubyte[] to make it work which doesn't

Re: Is there a 128-bit integer in D?

2016-05-22 Thread tcak via Digitalmars-d-learn
On Saturday, 21 May 2016 at 09:56:51 UTC, Stefan Koch wrote: On Saturday, 21 May 2016 at 09:43:38 UTC, Saurabh Das wrote: I see that 'cent' and 'ucent' are reserved for future use but not yet implemented. Does anyone have a working implementation of these types? Alternatively, is there an

Re: multithreading profiling

2016-04-18 Thread tcak via Digitalmars-d-learn
On Monday, 18 April 2016 at 13:33:20 UTC, jj75607 wrote: Hello! Is it possible to start profiling on multithreaded app with Dmd? https://issues.dlang.org/show_bug.cgi?id=14511 is open. I am doing wrong or why this program segfaults if compiled with profiler hooks? import core.atomic;

Re: Fiber and Thread Communication

2016-04-08 Thread tcak via Digitalmars-d-learn
On Friday, 8 April 2016 at 15:33:46 UTC, Dicebot wrote: On Friday, 8 April 2016 at 14:08:39 UTC, Nordlöw wrote: So a TId can represent either a thread or a fiber? AFAIR, yes (I haven't used std.concurrency in a long while, telling all from memory only). yes what? Thread or Fiber. ---

Segmentation Fault on rt.tlsgc.init

2016-04-05 Thread tcak via Digitalmars-d-learn
If I create many threads (starts, does a short work, and ends) repeatedly (>10,000), at some point rt.tlsgc.init() gives SEGMENTATION_FAULT. It doesn't check whether malloc fails to allocate any memory, and I cannot find the source code of "rt.sections.initTLSRanges()" anywhere. Is it left

Re: Convert wchar* to wstring?

2016-04-04 Thread tcak via Digitalmars-d-learn
On Tuesday, 5 April 2016 at 01:21:55 UTC, Thalamus wrote: I'm sorry for this total newbie question, but for some reason this is eluding me. I must be overlooking something obvious, but I haven't been able to figure this out and haven't found anything helpful. I am invoking an entry point in

Re: Catching thread creation error

2016-04-04 Thread tcak via Digitalmars-d-learn
On Monday, 4 April 2016 at 20:28:13 UTC, tcak wrote: In my server program, when a request comes, I create a new thread for that. I put memory limit to program with setrlimit. So, when the limit is reached, new thread cannot be created. I want to tell client back that there is system

Catching thread creation error

2016-04-04 Thread tcak via Digitalmars-d-learn
In my server program, when a request comes, I create a new thread for that. I put memory limit to program with setrlimit. So, when the limit is reached, new thread cannot be created. I want to tell client back that there is system problem. But catching "Throwable" does not suffice for this

How big memory is allocated by GC?

2016-04-03 Thread tcak via Digitalmars-d-learn
Is there any way to know how big memory has been allocated by GC currently (or in the last scan)? I want to limit the total memory usage of program manually. So, while I am allocating some space (in server program), if the desired memory will exceed the limit, I will fail the operation

Minimise and collect by GC when OutOfMemory

2016-02-25 Thread tcak via Digitalmars-d-learn
Would it be a good idea to call "collect" and "minimize" methods of core.memory.GC when OutOfMemory error is received FOR A LONG RUNNING PROGRAM? or there won't be any benefit of that? Example program: A web server that allocates and releases memory from heap continuously.

What happens if memory allocation fails?

2016-02-20 Thread tcak via Digitalmars-d-learn
This is not easy to try. So I need ask, maybe someone has experienced. What happens if memory allocation fails with "new" keyword? Does it throw an exception? throwable? All I want is to be able to catch OutOfMemory event, and take other steps based on that.

Re: Get memory usage report from GC

2016-02-19 Thread tcak via Digitalmars-d-learn
On Saturday, 20 February 2016 at 05:55:26 UTC, Jon D wrote: On Saturday, 20 February 2016 at 05:34:01 UTC, tcak wrote: On Saturday, 20 February 2016 at 05:33:00 UTC, tcak wrote: Is there any way (I checked core.memory already) to collect report about memory usage from garbage collector? So, I

Get memory usage report from GC

2016-02-19 Thread tcak via Digitalmars-d-learn
Is there any way (I checked core.memory already) to collect report about memory usage from garbage collector? So, I can see a list of pointer and length information. Since getting this information would require another memory area in heap, it could be like logging when report is asked. My

Re: What is the best way to stop App after exception?

2016-02-15 Thread tcak via Digitalmars-d-learn
On Monday, 15 February 2016 at 11:38:05 UTC, Suliman wrote: I have got class Config with method parseconfig. I need terminate App if parsing of config was failed. The problem that I do not know how to do it better. void parseconfig() { try { //something go wrong } catch(Exception e) {

Re: Singleton, alias to self?

2016-02-14 Thread tcak via Digitalmars-d-learn
On Sunday, 14 February 2016 at 12:56:51 UTC, Vladde Nordholm wrote: I'm not sure of how to use alias efficiently, so I want to know if I could somehow do this (psuedo-code) class Singleton { //So instead of calling `Singleton.getSingleton()` you just call `Singleton` alias this =

Index file for ddoc

2016-02-13 Thread tcak via Digitalmars-d-learn
Maybe I am missing, but I do not see any index file when html files are generated by ddoc. Is there any way to generate index file automatically, so, a tree like links will be listed all created documentation files? If the problem is about the possibility of having index.d and it would be

Re: wrapSocket for socket_t? As wrapFile for FILE*

2016-02-13 Thread tcak via Digitalmars-d-learn
On Sunday, 14 February 2016 at 04:13:12 UTC, Beginner-8 wrote: Hi! Anyone seen Socket constructor which uses already available socket of socket_t type? I am need to use already connected socket imported from C library without closing them after using. One of the constructors of class

Re: std.socket question

2016-02-04 Thread tcak via Digitalmars-d-learn
On Thursday, 4 February 2016 at 06:40:15 UTC, sanjayss wrote: Are the functions lastSocketError() and wouldHaveBlocked() from std.socket thread-safe? i.e. can they be reliably used to see the status of the last socket call when sockets are being read/written in multiple threads? Not directly

Re: What reasons are known a thread stops suddenly?

2016-02-04 Thread tcak via Digitalmars-d-learn
On Friday, 5 February 2016 at 06:23:09 UTC, Daniel Kozak wrote: V Fri, 05 Feb 2016 03:47:40 + tcak via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> napsáno: [...] Did you try catch Throwable instead of Exception? Undid the fix, and wrapped the problem causing functio

Re: What reasons are known a thread stops suddenly?

2016-02-04 Thread tcak via Digitalmars-d-learn
On Thursday, 4 February 2016 at 22:27:31 UTC, Ali Çehreli wrote: On 02/04/2016 12:25 PM, tcak wrote: > void threadFunc(){ > scope(exit){ > writeln("Leaving 2: ", stopRequested); > } > > > while( !stopRequested ){ > /* THERE IS NO "RETURN" HERE AT ALL */ > } > >

Re: What reasons are known a thread stops suddenly?

2016-02-04 Thread tcak via Digitalmars-d-learn
On Friday, 5 February 2016 at 03:47:40 UTC, tcak wrote: On Thursday, 4 February 2016 at 22:27:31 UTC, Ali Çehreli wrote: On 02/04/2016 12:25 PM, tcak wrote: > [...] That would happen when there is an exception. > [...] If a thread is terminated with an exception, its stack is unwound and

What reasons are known a thread stops suddenly?

2016-02-04 Thread tcak via Digitalmars-d-learn
I have implemented a standalone HTTP server. So everything is in single executable. Requests come, for responding a new thread is started, etc. To listen new socket connections, and socket events, a single thread is used (Call this event listener thread). Everything works perfectly. Firefox

Defining event handlers for function, method, or shared method

2016-01-26 Thread tcak via Digitalmars-d-learn
In many multi threading module designs of mine, I generally design a base class, and this class have some events. Exempli gratia: void eventOnStart(); void eventOnStop(); void eventOnItemAdded( size_t itemIndex ); There is this problem though. I need/want this class to be able to bind a

Re: Defining event handlers for function, method, or shared method

2016-01-26 Thread tcak via Digitalmars-d-learn
On Tuesday, 26 January 2016 at 19:42:42 UTC, tcak wrote: On Tuesday, 26 January 2016 at 19:22:58 UTC, Ali Çehreli wrote: [...] Hmm. Your example works fine for functions, but I can't pass a method instead of function as alias. Check my example: [...] Edit: ... "I guess because it is

Re: Defining event handlers for function, method, or shared method

2016-01-26 Thread tcak via Digitalmars-d-learn
On Tuesday, 26 January 2016 at 19:22:58 UTC, Ali Çehreli wrote: On 01/26/2016 10:41 AM, tcak wrote: > I need/want this class to be able to bind > a function, a method, or a shared method. From the perspective of class > design, there shouldn't be any > difference. Its purpose is to let know

core.thread.Thread.start is marked as "nothrow" but documentation says it throws

2016-01-23 Thread tcak via Digitalmars-d-learn
https://dlang.org/phobos/core_thread.html#.Thread final nothrow Thread.start() Looking at the code, no "throw new ..." is seen, but the function "onThreadError" is called which has "throw" in it. Most weird thing is that "onThreadError" function is marked as "nothrow" but it still throws.

Re: Define "createXXX" functions for the constructors of class XXX

2016-01-23 Thread tcak via Digitalmars-d-learn
On Saturday, 23 January 2016 at 19:42:29 UTC, Johan Engelen wrote: Hi all, While trying to interface C++ and D, I have to new a few D objects in C++ code. I am doing this using a D function: "XXX createXXX(...) { return new XXX(...); }". I am sure there must be some great way to

Re: Changing Name of a thread

2016-01-09 Thread tcak via Digitalmars-d-learn
On Saturday, 9 January 2016 at 11:02:53 UTC, Keywan Ghadami wrote: Hello, i am trying to the set the name of thread with: import core.thread; auto thisThread = Thread.getThis(); thisThread.name = "kiwi"; but GDB prints the name of the programm ("helloworld") [Thread debugging

Re: Linking a DLL to a DLL with packages

2016-01-09 Thread tcak via Digitalmars-d-learn
On Friday, 8 January 2016 at 12:13:15 UTC, Benjamin Thaut wrote: On Thursday, 7 January 2016 at 19:29:43 UTC, Thalamus wrote: Hi everyone, First off, I've been working with D for a couple of weeks now and I think it's the bee's knees! :) Except for DLLs. thanks! :) Dlls don't currently

Re: Calling functions from other files/modules

2016-01-06 Thread tcak via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 23:12:27 UTC, Namal wrote: On Wednesday, 6 January 2016 at 23:06:38 UTC, Adam D. Ruppe wrote: On Wednesday, 6 January 2016 at 23:00:43 UTC, Namal wrote: I just tried to import one module with a main into another, but I get this: You can't have two mains, but

Re: Strange 'memset' error when using std.range.repeat and std.array.array

2016-01-04 Thread tcak via Digitalmars-d-learn
On Monday, 4 January 2016 at 10:50:17 UTC, Ur@nuz wrote: Sorry, the actual code is: ... lines ~= ' '.repeat.take(newIndentCount).array; ...with character quotes. But it still fails with error described in stack trace in Gcx.bigAlloc() What's your OS? On Linux x64, it works without any

Re: How to use GDC to get .a file on Linux?

2015-12-27 Thread tcak via Digitalmars-d-learn
On Sunday, 27 December 2015 at 15:19:21 UTC, FrankLike wrote: Hi, Now I need get the .a file on Linux,target system is ARM. If you use gcc ,you will use the 'ar' to get .a file, but how to do by GDC ? And how to get the execute file by .a file and .d file? Thank you. I couldn't have

Re: basic interactive readf from stdin

2015-12-26 Thread tcak via Digitalmars-d-learn
On Saturday, 26 December 2015 at 20:19:08 UTC, Adam D. Ruppe wrote: On Saturday, 26 December 2015 at 20:11:27 UTC, karthikeyan wrote: I experience the same as the OP on Linux Mint 15 with dmd2.069 and 64 bit machine. I have to press enter twice to get the output. I read

Convert to string an enum item

2015-12-23 Thread tcak via Digitalmars-d-learn
[code] import std.stdio; import std.conv; enum Values: ubyte{ One = 1, Two = 2 } void main(){ writeln( std.conv.to!string( Values.One ) ); } [/code] Output is "One". casting works, but to be able to cast correctly, I need to tell compiler that it is "ubyte". Isn't there any

Re: Socket - handling large numbers of incoming connections

2015-12-21 Thread tcak via Digitalmars-d-learn
On Monday, 21 December 2015 at 20:53:14 UTC, Jakob Jenkov wrote: On Monday, 21 December 2015 at 20:20:44 UTC, Stefan wrote: How about https://github.com/dcarp/asynchronous ? Asyncio Socket handling is sometimes quite nice. It's performance is okay for nearly no effort and the code looks clean.

Re: Template specialization using traits?

2015-12-21 Thread tcak via Digitalmars-d-learn
On Monday, 21 December 2015 at 11:12:10 UTC, Jonathan M Davis wrote: On Monday, 21 December 2015 at 11:07:16 UTC, Jonathan M Davis wrote: For your example to work with template constraints, the most straightforward solution would be void func(T)(T t) if(!isIntegral!T) { writeln(1); }

Re: Can't debug my solution

2015-12-19 Thread tcak via Digitalmars-d-learn
On Saturday, 19 December 2015 at 20:52:41 UTC, Matheus Reis wrote: Hello, people! I'm Matheus, a 20 y/o game developer who wants to get started with D. It has really caught my attention, and I've been playing with it for some hours now. I've got it all working (without some "phobos.lib", is

Re: Error 42: Symbol Undefined __lseeki64

2015-12-16 Thread tcak via Digitalmars-d-learn
On Wednesday, 16 December 2015 at 18:30:41 UTC, Byron Heads wrote: On Wednesday, 16 December 2015 at 18:21:33 UTC, Byron Heads wrote: On Wednesday, 16 December 2015 at 18:14:35 UTC, Byron Heads wrote: [...] Commenting out gzclose(fpGZip); allows it to compile.. Submitted reduced case as

Re: Error: undefined identifier 'selector'

2015-12-14 Thread tcak via Digitalmars-d-learn
On Monday, 14 December 2015 at 20:46:41 UTC, Mike McKee wrote: When I run this piece of code: // FROM: https://dlang.org/spec/objc_interface.html module main; [...] UDA s cannot be used for functions/methods AFAIK.

Re: Very very noobie question about how imports work.

2015-12-10 Thread tcak via Digitalmars-d-learn
On Friday, 11 December 2015 at 04:09:19 UTC, Chris Wright wrote: On Fri, 11 Dec 2015 03:20:29 +, J Smith wrote: How do I make it so that I can import and use the contents of lib.d inside of testlib.d. If you are not compiling everything in one step, the -I flag allows you to specify

Re: Very very noobie question about how imports work.

2015-12-10 Thread tcak via Digitalmars-d-learn
On Friday, 11 December 2015 at 03:20:29 UTC, J Smith wrote: Say I have a project with the files structured like this. package-name/ src/ package-name/ lib.d test/ testlib.d How do I make it so that I can import and use the contents of lib.d inside of

Re: Using phobos as shared library for multiple binaries

2015-12-05 Thread tcak via Digitalmars-d-learn
On Saturday, 5 December 2015 at 21:49:52 UTC, Ralf wrote: Hi, I've written several small command-line utilities in D that are to be shipped together in one package. Each one of them only would be only a few kB in size, but they end up being ~1Mb, I assume because every one links statically

Re: Using enums as function parameters (in a minimized way)

2015-12-01 Thread tcak via Digitalmars-d-learn
On Tuesday, 1 December 2015 at 10:50:04 UTC, Rikki Cattermole wrote: On 01/12/15 11:44 PM, Ozan wrote: Hi Let's say we have an enum like enum SomethingAboutChristmas { SantaClaus, Angel, Tree } and want to use it in a function like void goingChristmas(SomethingAboutChristmas

Re: Using enums as function parameters (in a minimized way)

2015-12-01 Thread tcak via Digitalmars-d-learn
On Tuesday, 1 December 2015 at 13:03:37 UTC, tcak wrote: On Tuesday, 1 December 2015 at 10:50:04 UTC, Rikki Cattermole wrote: [...] This is like: Q) I want to write an OS. How? A) Write in assembly. What Ozan says is logical. Compiler should assume it in that way normally. I have

Re: std.socket replacement

2015-11-29 Thread tcak via Digitalmars-d-learn
On Sunday, 29 November 2015 at 08:56:30 UTC, tired_eyes wrote: I was a bit surprised to see that std.socket is deprecated as of 2.069. Just curious, what's wrong with it? And what should I use as a replacement? I know there is vibe.socket, but I don't want to include fullstack web framework as

Re: Multithreaded HTTP Download

2015-11-28 Thread tcak via Digitalmars-d-learn
On Saturday, 28 November 2015 at 07:05:55 UTC, Mike McKee wrote: Hey guys, as it turns out, someone on stackoverflow.com pointed out in a Perl version of this question that the Bash example that was given is really buggy and doesn't make sense. They say that trying to download a single file

Re: Retrieving call expression of a function

2015-11-28 Thread tcak via Digitalmars-d-learn
On Saturday, 28 November 2015 at 15:41:59 UTC, Quentin Ladeveze wrote: On Saturday, 28 November 2015 at 15:22:51 UTC, tcak wrote: On Saturday, 28 November 2015 at 15:02:32 UTC, Quentin Ladeveze wrote: Hi, Is it possible to retrieve the calling expression of a function ? Something like that

Re: Retrieving call expression of a function

2015-11-28 Thread tcak via Digitalmars-d-learn
On Saturday, 28 November 2015 at 15:02:32 UTC, Quentin Ladeveze wrote: Hi, Is it possible to retrieve the calling expression of a function ? Something like that --- import std.stdio; void funcTest(int x, float y) { writefln(get_call()); } void main() { float x = 0.2; funcTest(1+2,

switch with enum

2015-11-24 Thread tcak via Digitalmars-d-learn
I have seen a code a while ago, but even by looking at documentation, I couldn't have found anything about it. Let's say I have defined an enum; enum Status: ubyte{ Busy = 1, Active = 2 } and received a ubyte value from user. ubyte userValue; I want to switch over userValue, but that

Re: switch with enum

2015-11-24 Thread tcak via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 03:59:01 UTC, Steven Schveighoffer wrote: On 11/24/15 10:51 PM, tcak wrote: I have seen a code a while ago, but even by looking at documentation, I couldn't have found anything about it. Let's say I have defined an enum; enum Status: ubyte{ Busy = 1,

Re: String interpolation

2015-11-10 Thread tcak via Digitalmars-d-learn
On Tuesday, 10 November 2015 at 11:22:56 UTC, wobbles wrote: On Tuesday, 10 November 2015 at 10:41:52 UTC, tired_eyes wrote: On Tuesday, 10 November 2015 at 10:33:30 UTC, Tobias Pankrath wrote: On Tuesday, 10 November 2015 at 10:21:32 UTC, tired_eyes wrote: [...] std.string.format and

Compile time digest error

2015-11-09 Thread tcak via Digitalmars-d-learn
[code] private static import std.digest.md; public enum HashValue = std.digest.digest.digest!( std.digest.md.MD5)( "" ); void main(){} [/code] [output] dmd main.d /usr/include/dmd/phobos/std/digest/md.d(202): Error: reinterpreting cast from uint[16] to ubyte* is not supported in CTFE

Parse d source file by using compiler

2015-11-08 Thread tcak via Digitalmars-d-learn
I checked for a flag in this page http://dlang.org/dmd-linux.html , but couldn't have found any for this purpose. Is there a way to parse a d source file so it generates a tree in JSON, XML, or something-that-can-be-processed-easily file format? --- My real purpose: I need to generate hash

Re: method has no return statement with switch

2015-11-06 Thread tcak via Digitalmars-d-learn
On Saturday, 7 November 2015 at 00:21:57 UTC, crimaniak wrote: Hi! I have the error message: source/url.cache.d(20,16): Error: function url.Cache.UrlCache.doRequest has no return statement, but is expected to return a value of type string [...] Because the "switch" is marked as "final",

Re: Associative array with duplicated keys?

2015-11-05 Thread tcak via Digitalmars-d-learn
On Thursday, 5 November 2015 at 08:55:10 UTC, Andrea Fontana wrote: Check this: http://dpaste.dzfl.pl/ebbb3ebac60e It doesn't give any error or warning. And writeln seems confused (do you see that "," at the end?) I am sure the coder of writeln was lazy to prevent putting ", " after last

Re: good reasons not to use D?

2015-10-31 Thread tcak via Digitalmars-d-learn
On Saturday, 31 October 2015 at 14:37:23 UTC, rumbu wrote: On Friday, 30 October 2015 at 10:35:03 UTC, Laeeth Isharc wrote: I'm writing a talk for codemesh on the use of D in finance. Any other thoughts? For finance stuff - missing a floating point decimal data type. Things like 1.1 + 2.2 =

Re: I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread tcak via Digitalmars-d-learn
On Wednesday, 28 October 2015 at 11:48:27 UTC, pineapple wrote: On Wednesday, 28 October 2015 at 11:40:14 UTC, tcak wrote: The "writebuffer" is defined to take an array as parameter. Yet, you are passing a pointer and a length to it. Instead, pass the parameter "str" to it directly. Also, you

Re: I'm getting an unhelpful linker error, what've I got wrong?

2015-10-28 Thread tcak via Digitalmars-d-learn
On Wednesday, 28 October 2015 at 11:11:01 UTC, pineapple wrote: When I attempt to compile my code I get the same linker error with both dmd and ldc2. I know where the problematic code is, as I don't get the error when I comment out lines 102 through 107, but I don't understand why it's bad. I

Re: How coding bootloader with (Asm+Dlang)?

2015-10-28 Thread tcak via Digitalmars-d-learn
On Wednesday, 28 October 2015 at 15:23:11 UTC, guodemone wrote: I would like to use (Dlang + nasm) to write bootloader, how to write? Start from here: http://wiki.osdev.org/D_Bare_Bones I would suggest you to start by learning to do it with C first though. There are too many documents

Mixin template parameter that is an undefined variable

2015-10-23 Thread tcak via Digitalmars-d-learn
[code] mixin template Test(alias a){ int a; } void main(){ mixin Test!blah; } [/code] Compiler says it doesn't know about "blah". My purpose is to define the parameter as a variable. Is that possible?

How to check whether an empty array variable is null?

2015-10-10 Thread tcak via Digitalmars-d-learn
[code] int[] list; list = new int[0]; std.stdio.writeln("Is Null ? ", (list is null)); [/code] Result is "Is Null? true". Is this the correct behaviour? I would expect compiler to point to an address in the heap, but set the length as 0. So, it wouldn't return null,

Re: How to check whether an empty array variable is null?

2015-10-10 Thread tcak via Digitalmars-d-learn
On Saturday, 10 October 2015 at 20:07:11 UTC, Jonathan M Davis wrote: On Saturday, October 10, 2015 15:20:02 tcak via Digitalmars-d-learn wrote: [code] int[] list; list = new int[0]; std.stdio.writeln("Is Null ? ", (list is null)); [/code] Result is &quo

Re: Tell GC to use shared memory

2015-10-08 Thread tcak via Digitalmars-d-learn
On Thursday, 8 October 2015 at 05:46:31 UTC, ketmar wrote: On Thursday, 8 October 2015 at 04:38:43 UTC, tcak wrote: Is it possible to modify GC (without rebuilding the compiler), so it uses a given shared memory area instead of heap for allocations? sure. you don't need to rebuild the

Check template parameter whether it has "length"

2015-10-08 Thread tcak via Digitalmars-d-learn
I am "trying" to write a function that takes an array of items, and returns the length of longest item. [code] size_t maxLength(A)( const A[] listOfString ) if( __traits( hasMember, A, "length" ) ) { return 0; // not implemented yet } [/code] I tried it with if( __traits( compiles,

Re: Check template parameter whether it has "length"

2015-10-08 Thread tcak via Digitalmars-d-learn
On Thursday, 8 October 2015 at 09:50:12 UTC, John Colvin wrote: On Thursday, 8 October 2015 at 09:29:30 UTC, tcak wrote: [...] I'm 99% sure something like __traits(hasMember, int[], "length" ) should evaluate to true. Please file a bug at issues.dlang.org I notice it also doesn't work for

Tell GC to use shared memory

2015-10-07 Thread tcak via Digitalmars-d-learn
Is it possible to modify GC (without rebuilding the compiler), so it uses a given shared memory area instead of heap for allocations?

What is the postfix for min long value?

2015-10-06 Thread tcak via Digitalmars-d-learn
While writing max ulong value, I added the "u" postfix. So compiler accepted it as ulong value (That's my interpretation if correct on compiler's side). writeln( 18_446_744_073_709_551_615u ); But when I try to print out minimum value of long, compiler says Error: signed integer overflow

Bug? 0 is less than -10

2015-10-06 Thread tcak via Digitalmars-d-learn
Maybe I am just too stressed out to see the problem. [code] import std.stdio; void main(){ size_t dec = 0; writeln( dec, " ", (dec <= -10), " ", (dec >= 10), " ", ((dec <= -10) || (dec >= 10)) ); } [/code] [output] 0 true false true [/output] How is it generating "true" for (dec

Re: Server side command execution.

2015-09-27 Thread tcak via Digitalmars-d-learn
On Sunday, 27 September 2015 at 23:56:10 UTC, holo wrote: Hello Im trying to execute commands on server side. Here is my server based on other example from forum: [...] You are comparing whole buffer to "exit"

Re: Client socket sending data only one time.

2015-09-24 Thread tcak via Digitalmars-d-learn
On Thursday, 24 September 2015 at 14:20:39 UTC, holo wrote: Hello I'm trying to connect to server and send data, with such simple client: #!/usr/bin/rdmd import std.stdio; import std.socket; import std.socketstream; import std.process; import std.conv; import core.time; void main() {

Re: Why is the constructor of B called?

2015-09-23 Thread tcak via Digitalmars-d-learn
On Wednesday, 23 September 2015 at 21:14:17 UTC, Adam D. Ruppe wrote: On Wednesday, 23 September 2015 at 21:08:37 UTC, tcak wrote: I wouldn't expect B's constructor to be called at all unless "super" is used there. "If no call to constructors via this or super appear in a constructor, and

Why is the constructor of B called?

2015-09-23 Thread tcak via Digitalmars-d-learn
[code] import std.stdio; class B { this() { writeln("B.constructor"); foo(); } void foo() { writeln("B.foo"); } } class D : B { this() { writeln("D.constructor"); } override

Re: version and configuration

2015-09-12 Thread tcak via Digitalmars-d-learn
On Saturday, 12 September 2015 at 14:41:45 UTC, Spacen Jasset wrote: If I say this in one module: version = current version (Current) { version = featurea; version = featureb; version = featurec; } It appears that I can't put this in a module and import it elsewhere to test the

  1   2   3   >