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 versi

Re: website update

2015-08-10 Thread tcak via Digitalmars-d-learn
On Monday, 10 August 2015 at 10:34:56 UTC, Tony wrote: It looks like this page: http://dlang.org/hash-map.html Should have the override keyword added the the member functions in Foo: class Foo { int a, b; size_t toHash() { return a + b; } bool opEquals(Object o) { F

Trouble with template parameter matching

2015-08-02 Thread tcak via Digitalmars-d-learn
[code] void func1(N)( const N name ) if( is(N: string) || is(N: char[]) ) { func2( name ); } void func2(N)( const N name ) if( is(N: string) || is(N: char[]) ) {} void main(){ char[] blah = ['b', 'l', 'a', 'h']; func1( blah ); //func1( "blah" );

Re: Changes on dynamic shared library writing

2015-07-29 Thread tcak via Digitalmars-d-learn
On Thursday, 30 July 2015 at 03:52:16 UTC, Rikki Cattermole wrote: On 30/07/2015 8:27 a.m., tcak wrote: On Wednesday, 29 July 2015 at 19:41:14 UTC, tcak wrote: After a long time (Failed many times before), I checked the page http://dlang.org/dll-linux.html again. It shows a message on top say

Re: Changes on dynamic shared library writing

2015-07-29 Thread tcak via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 19:41:14 UTC, tcak wrote: After a long time (Failed many times before), I checked the page http://dlang.org/dll-linux.html again. It shows a message on top saying that preliminary and subject to change. Exactly what changes are expected? Where can I learn about t

Changes on dynamic shared library writing

2015-07-29 Thread tcak via Digitalmars-d-learn
After a long time (Failed many times before), I checked the page http://dlang.org/dll-linux.html again. It shows a message on top saying that preliminary and subject to change. Exactly what changes are expected? Where can I learn about them? I would do tests again with dynamic library writing

Re: No Unix socket support?

2015-07-29 Thread tcak via Digitalmars-d-learn
On Wednesday, 29 July 2015 at 13:39:33 UTC, simendsjo wrote: Is there no Unix socket support in Phobos? Or vibe? Or any other library? I've found some discussions: * https://issues.dlang.org/show_bug.cgi?id=9384 * http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/10870/ ,

Re: Implicit conversion in constructor

2015-07-17 Thread tcak via Digitalmars-d-learn
On Saturday, 18 July 2015 at 02:23:26 UTC, rcorre wrote: Is there any reason why implicit conversion from Foo to Thing is permitted in a regular method but not in a constructor? Trying to figure out whether this is a bug or some sort of constructor-specific safety precaution. struct Thing {

Re: Delayed const variable initialization

2015-07-13 Thread tcak via Digitalmars-d-learn
On Monday, 13 July 2015 at 09:08:14 UTC, Yuxuan Shui wrote: On Monday, 13 July 2015 at 09:05:25 UTC, ketmar wrote: On Mon, 13 Jul 2015 08:56:05 +, Yuxuan Shui wrote: [...] as i wrote, what you really want is the ability to assign to `const`, which is forbidden in D. initialization of `x

How to abort compilation

2015-07-12 Thread tcak via Digitalmars-d-learn
To keep the story short (if necessary, I can explain the use-case), if there any way to abort compilation with a message. I would use "static if" or "version" to check a situation, and "pragma msg" to show a message. But I couldn't have found any "proper" way to abort compilation.

Re: Function pointer array slice?

2015-07-11 Thread tcak via Digitalmars-d-learn
On Saturday, 11 July 2015 at 09:30:43 UTC, Tofu Ninja wrote: So simple syntax question, how do I make an array slice of function pointers? I just have no idea where to put the [] on something like void function() nothrow pure @nogc @safe arrayName; Or should I just alias it and make an a

How to get value of enum without casting

2015-07-09 Thread tcak via Digitalmars-d-learn
[code] const enum FieldLength: uint{ Title = 64 } const string SQL1 = "title CHAR(" ~ std.conv.to!string( FieldLength.Title ) ~ ")"; void main() { writeln( FieldLength.Title ); writeln( SQL1 ); } [/code] Result is --- Title Char(Title) I can do cast(uint

How to keep executed shell running after program exits

2015-07-08 Thread tcak via Digitalmars-d-learn
I have written a code to run gnuplot. [code] ... auto script = std.stdio.File("/tmp/waveletscript.gnuplot", "w"); script.writeln("set term wxt 1; plot '/tmp/wavelet1.dat';"); script.writeln("set term wxt 2; plot '/tmp/wavelet2.dat';"); script.writeln("set term wxt 3; plot '/tmp/wavelet3.dat';");

Re: Squaring Arrays without Overlapping Array Error

2015-07-07 Thread tcak via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 08:06:50 UTC, tcak wrote: On Tuesday, 7 July 2015 at 05:27:10 UTC, jmh530 wrote: [...] I have never used arrays in that way before, though I don't get why you are writing return line in that way. Shouldn't it be like `return (x[] * x[]);` ? But, yes, the result s

Re: Squaring Arrays without Overlapping Array Error

2015-07-07 Thread tcak via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 05:27:10 UTC, jmh530 wrote: If I call a function like int[] square_array(int[] x) { return x[] *= x[]; } I get an error that there is an overlapping array in a vector operation. I guess this makes sense as the lhs and rhs are occupying the same memory. Never

Re: generic cast(unshared) ?

2015-06-30 Thread tcak via Digitalmars-d-learn
On Sunday, 28 June 2015 at 23:42:47 UTC, Timothee Cour wrote: How would I cast away shared for a given expression? I can write it for a specific type but I'd like to have a generic way to do so. Also, Unqual doesn't help here. Normally, "cast()" removes "shared" from a type. BUT, sometimes i

Re: Using C library libsndfile with D

2015-06-25 Thread tcak via Digitalmars-d-learn
On Thursday, 25 June 2015 at 19:54:34 UTC, Ali Çehreli wrote: On 06/25/2015 12:51 PM, bachmeier wrote: pragma(lib, "sndfile"); This is the first time I've heard of pragma(lib). It's a nice feature that should be added to the compiler documentation. They are all here: http://dlang.or

Re: function default parameters lost

2015-06-25 Thread tcak via Digitalmars-d-learn
On Thursday, 25 June 2015 at 04:43:51 UTC, Paul D Anderson wrote: I'm trying to pass a function pointer while keeping the default parameter values intact. Given the following: [...] I filed a bug about 2-3 months ago about default parameters similar to yours. My guess is that it hasn't been

Re: Defining constant values in struct

2015-06-16 Thread tcak via Digitalmars-d-learn
On Tuesday, 16 June 2015 at 21:38:22 UTC, jklp wrote: On Tuesday, 16 June 2015 at 21:17:37 UTC, tcak wrote: [...] Do i miss a detail in your requirement ? --- struct TableSchema{ const string TABLE = "users"; struct FieldTypes{ static const string ID = "BIGINT

Defining constant values in struct

2015-06-16 Thread tcak via Digitalmars-d-learn
As far as I known, when I define a string with enum and it is used at different parts of code, that string is repeated again and again in executable file instead of passing a pointer to string. So, using enum with string doesn't seem like a good idea. Hence, I defined string as const to make i

Does using "const" keyword for scalar parameters mean anything?

2015-06-04 Thread tcak via Digitalmars-d-learn
[code] void test( const int a ){} [/code] Does that "const" make any difference at all? At the end, it is a scalar, and passed as value.

Re: What does program do when array is returned from function?

2015-06-04 Thread tcak via Digitalmars-d-learn
On Thursday, 4 June 2015 at 09:42:04 UTC, Marc Schütz wrote: On Thursday, 4 June 2015 at 07:20:24 UTC, Daniel Kozák wrote: On Thu, 04 Jun 2015 07:03:30 + tcak via Digitalmars-d-learn wrote: [code] char[] test(){ auto t = new char[5]; return t; } [/code] Is the test function

What does program do when array is returned from function?

2015-06-04 Thread tcak via Digitalmars-d-learn
[code] char[] test(){ auto t = new char[5]; return t; } [/code] Is the test function returning just a pointer from heap or does copy operation? It is not obvious what it does, and I am trying to avoid doing this always.

Reset Range

2015-05-30 Thread tcak via Digitalmars-d-learn
I have never interested in "Range" topic till now, but with Walter's presentation, I took a look at it today. Ali has a nice lesson page about it (http://ddili.org/ders/d.en/ranges.html). What I don't get is the mechanism to reset a range. I mean, you use a range with foreach, but then it is

Get index of string in array at compile time

2015-05-29 Thread tcak via Digitalmars-d-learn
I have define an immutable string array: [code] immutable string[] placeHolderDefinitionList = [ "", "" ]; [/code] I need to get index of a string at compile time. So I have written a function as below: [code] public size_t getPlaceholderIndex(string PlaceHolderText)( size_t

Re: Checking template parameter types of class

2015-05-24 Thread tcak via Digitalmars-d-learn
On Monday, 25 May 2015 at 04:07:06 UTC, Jonathan M Davis wrote: On Monday, May 25, 2015 03:42:22 tcak via Digitalmars-d-learn wrote: Well, if I do not check the line number of error, this happens. It was giving error on the line of creating a new instance. Line 243: auto fileResourceList

Re: Checking template parameter types of class

2015-05-24 Thread tcak via Digitalmars-d-learn
On Monday, 25 May 2015 at 03:35:22 UTC, Jonathan M Davis wrote: On Monday, May 25, 2015 03:19:29 tcak via Digitalmars-d-learn wrote: Is there any syntax for something like that: class Resource(T) if( is(T: FileResource) ){ } I tried it as above, but it is not accepted. Maybe I am following

Checking template parameter types of class

2015-05-24 Thread tcak via Digitalmars-d-learn
Is there any syntax for something like that: class Resource(T) if( is(T: FileResource) ){ } I tried it as above, but it is not accepted. Maybe I am following a wrong syntax. I tried class Resource(T: FileResource){ } But it is not accepted as well.

Re: Weird result of getsockopt

2015-05-24 Thread tcak via Digitalmars-d-learn
On Sunday, 24 May 2015 at 16:51:44 UTC, CodeSun wrote: Hello guys, Today, I found a weird problem when I was learning to enable SO_KEEPALIVE for a specific socket. I use setsockopt to enable keepalive firstly, and then use getsockopt to show if it is enabled correctly. My code snippet is lis

Re: is expression with static if matches wrong type

2015-05-22 Thread tcak via Digitalmars-d-learn
On Saturday, 23 May 2015 at 04:35:55 UTC, tcak wrote: [code] import std.stdio; public void setMarker(M)( size_t markerIndex, M markerValue ) if( is(M: ulong) || is(M: long) || is(M: uint) || is(M: int) || is(M: ushort) || is(M: short) ||

is expression with static if matches wrong type

2015-05-22 Thread tcak via Digitalmars-d-learn
[code] import std.stdio; public void setMarker(M)( size_t markerIndex, M markerValue ) if( is(M: ulong) || is(M: long) || is(M: uint) || is(M: int) || is(M: ushort) || is(M: short) || is(M: ubyte) || is(M: byte) || is(M: char

What is a mutable method?

2015-05-22 Thread tcak via Digitalmars-d-learn
I know there is mutable variables, but what is a mutable method? Error message says "mutable method project.mariadb.connector.ver2p1.resultset.ResultSetColumn.info is not callable using a const object".

Const is already there. It cannot deduce it

2015-05-18 Thread tcak via Digitalmars-d-learn
[code] void test(D)( const D data ) if( is(D: shared(char[]) ) ) { } void main() { char[] text = new char[4]; text[0] = 'a'; text[1] = 'b'; text[2] = 'c'; text[3] = 'd'; auto t = cast( shared(const(char[])) )text[1..2]; test( t ); } [/code] Error Messag

Re: Convert C array pointer to a D slice without data copy

2015-05-18 Thread tcak via Digitalmars-d-learn
On Monday, 18 May 2015 at 09:18:33 UTC, ParticlePeter wrote: I get the point to an array from a c function, the data size from another function. The data should be only readable at the D side, but I would like to use it as a D slice without copying the data. Is this possible ? char* dataPtr;

Re: pthread and GC

2015-05-13 Thread tcak via Digitalmars-d-learn
On Wednesday, 13 May 2015 at 07:29:51 UTC, Dicebot wrote: On Wednesday, 13 May 2015 at 07:04:39 UTC, tcak wrote: I am using pthread somewhere in program, and it creates an object. After a while, I see "core.thread.scanAllTypeImpl" error on gdb. Does this mean that pthread and GC are incompatib

pthread and GC

2015-05-13 Thread tcak via Digitalmars-d-learn
I am using pthread somewhere in program, and it creates an object. After a while, I see "core.thread.scanAllTypeImpl" error on gdb. Does this mean that pthread and GC are incompatible? Any solution without making too much code changes?

Re: Extreme memory usage when `synchronized( this )` is used

2015-05-11 Thread tcak via Digitalmars-d-learn
On Monday, 11 May 2015 at 15:38:55 UTC, Ali Çehreli wrote: On 05/11/2015 03:48 AM, tcak wrote: > I think `destroy`'s behaviour should be documented much better. Could others tell us the missing pieces please. Perhaps related to this discussion, the following document says "does not initiate a

Re: Extreme memory usage when `synchronized( this )` is used

2015-05-11 Thread tcak via Digitalmars-d-learn
On Monday, 11 May 2015 at 10:48:22 UTC, tcak wrote: On Monday, 11 May 2015 at 10:30:11 UTC, Daniel Kozak wrote: On Monday, 11 May 2015 at 10:24:57 UTC, Daniel Kozák wrote: On Mon, 11 May 2015 09:40:28 + tcak via Digitalmars-d-learn wrote: But yes I would say, it is not intentional

Re: Extreme memory usage when `synchronized( this )` is used

2015-05-11 Thread tcak via Digitalmars-d-learn
On Monday, 11 May 2015 at 10:30:11 UTC, Daniel Kozak wrote: On Monday, 11 May 2015 at 10:24:57 UTC, Daniel Kozák wrote: On Mon, 11 May 2015 09:40:28 + tcak via Digitalmars-d-learn wrote: But yes I would say, it is not intentional behaviour. It should use weak reference, so It would

Re: Extreme memory usage when `synchronized( this )` is used

2015-05-11 Thread tcak via Digitalmars-d-learn
On Monday, 11 May 2015 at 09:20:50 UTC, Daniel Kozák wrote: On Mon, 11 May 2015 09:09:07 + tcak via Digitalmars-d-learn wrote: I think synchronize(this) prevents GC from collect memory I am not sure whether this is expected behaviour from `synchronization` keyword. Similar code in

Re: Extreme memory usage when `synchronized( this )` is used

2015-05-11 Thread tcak via Digitalmars-d-learn
On Monday, 11 May 2015 at 09:09:09 UTC, tcak wrote: [code] import std.stdio; class Connection{ private void other() shared{} public void close() shared{ synchronized( this ){ other(); } } public void hasDat

Extreme memory usage when `synchronized( this )` is used

2015-05-11 Thread tcak via Digitalmars-d-learn
[code] import std.stdio; class Connection{ private void other() shared{} public void close() shared{ synchronized( this ){ other(); } } public void hasData() shared{ writeln("Has Data"); } } void main() {

Re: Memory usage tracking

2015-05-10 Thread tcak via Digitalmars-d-learn
On Sunday, 10 May 2015 at 10:50:40 UTC, weaselcat wrote: On Sunday, 10 May 2015 at 10:43:37 UTC, tcak wrote: On Sunday, 10 May 2015 at 09:44:42 UTC, tcak wrote: I am testing my web server right now. I started 5 separate consoles and continuously sending request by using "curl" to it. It uses

Re: Memory usage tracking

2015-05-10 Thread tcak via Digitalmars-d-learn
On Sunday, 10 May 2015 at 09:44:42 UTC, tcak wrote: I am testing my web server right now. I started 5 separate consoles and continuously sending request by using "curl" to it. It uses shared memory as well, thought from `ipcs -a`, I don't see more than necessary amount of allocation. At the

Memory usage tracking

2015-05-10 Thread tcak via Digitalmars-d-learn
I am testing my web server right now. I started 5 separate consoles and continuously sending request by using "curl" to it. It uses shared memory as well, thought from `ipcs -a`, I don't see more than necessary amount of allocation. At the moment, server received about 1.5M requests, and memo

Re: how does 'shared' affect member variables?

2015-05-09 Thread tcak via Digitalmars-d-learn
On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: What does 'shared' do to member variables? It makes sense to me to put it on a global variable, but what sense does it make putting it on a member of a class? What happens if you try to access a member of a class/struct instance from ano

Re: Lambda functions in D

2015-05-09 Thread tcak via Digitalmars-d-learn
On Saturday, 9 May 2015 at 11:20:10 UTC, Dennis Ritchie wrote: Hi, Can lambda functions or delegates in D to call themselves? Can I write something like this: - import std.stdio; void main() { auto fact = function (int x) => x * { if (x) fact(x - 1); }; assert(fact(10) ==

Re: Create custom data types

2015-04-29 Thread tcak via Digitalmars-d-learn
On Wednesday, 29 April 2015 at 17:17:07 UTC, Dennis Ritchie wrote: Hi, Is it possible to create simple D user-defined data types without the use of classes and other OOP? For example, in Ada is done as follows: - type balance is new Integer range -32_000 .. 32_000; I think you can use

Readonly-to-outside variable

2015-04-28 Thread tcak via Digitalmars-d-learn
Is there any way to define a variable or an attribute as read-only without defining a getter function/method for it? Thoughts behind this question are: 1. For every reading, another function call process for CPU while it could directly read the value from memory. 2. Repetition of same name fo

Re: How to turn an inout(Object) into a string

2015-04-25 Thread tcak via Digitalmars-d-learn
On Sunday, 26 April 2015 at 03:09:17 UTC, Meta wrote: The following code spits out pages of error messages, and it's driving me insane. I know that Object.toString only has a mutable variant, so how am I supposed to use writeln, toString, etc. with an inout, const, or immutable object? void m

Re: md5 return toHexString

2015-04-24 Thread tcak via Digitalmars-d-learn
On Friday, 24 April 2015 at 17:50:03 UTC, AndyC wrote: Hi All, I cannot seem to understand whats wrong with this: // main.d import std.stdio; import std.digest.md; import std.file; string md5sum(const string fname) { MD5 hash; File f = File(fname, "rb"); foreach( ubyte[] buf; f.by

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 14:49:24 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:42:33 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:30:07 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:25:56 UTC, Daniel Kozak wrote: On Thursday, 9 April 2015 at 14:16:00 UTC,

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
By the way, I am using "DMD64 D Compiler v2.067.0" on Ubuntu 14.04.

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 13:32:38 UTC, Adam D. Ruppe wrote: Don't use string == null, it is true for empty strings since null and an empty string are almost interchangable. You can try if(string is null) - is instead of ==. Though usually in D, I just if(string.length == 0) and treat empty

Re: Escape a string ?

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 13:09:57 UTC, Temtaime wrote: Hi ! I wonder how to escape a string in phobos ? For example auto a = [ "fooo\nbar" ]; auto b = format("%(%s%)", a); gives b: "fooo\nbar" Is there any other function to escape string? I'm looking for something that doesn't require to

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 12:06:49 UTC, Daniel Kozák wrote: On Thu, 09 Apr 2015 11:45:30 + tcak via Digitalmars-d-learn wrote: Can you post full example somewhere, this code works ok for me: import std.stdio; import std.datetime; class Response { public bool setCookie

Re: Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
On Thursday, 9 April 2015 at 11:45:31 UTC, tcak wrote: I have written a function as follows: public bool setCookie( string name, string value, long maxAgeInSeconds = long.min, string expiresOnGMTDate=null, string path=null, string domain=null,

Parameter is null by default. No value is given. Code says it is not null.

2015-04-09 Thread tcak via Digitalmars-d-learn
I have written a function as follows: public bool setCookie( string name, string value, long maxAgeInSeconds = long.min, string expiresOnGMTDate=null, string path=null, string domain=null, bool secure=false ) shared{ // if headers a

Implementing Iterator to support foreach

2015-04-07 Thread tcak via Digitalmars-d-learn
I am planning to implement "Iterator" class. But looking at "foreach" statement, it takes a range only. So is there any way other than returning an array from a function that is to be passed foreach statement? So I could write like that: Iterator iter = new MyList(); foreach(item; iter){ }

Re: Shall I use immutable or const while passing parameters to functions

2015-04-07 Thread tcak via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 15:51:59 UTC, bearophile wrote: tcak: void dataProcessor( string giveMeAllYourData ){} dataProcessor( cast( immutable )( importantData[5 .. 14] ) ); With Const, void dataProcessor( in char[] giveMeAllYourData ){} dataProcessor( cast( const )( importantData[5 ..

Shall I use immutable or const while passing parameters to functions

2015-04-07 Thread tcak via Digitalmars-d-learn
I have data in memory, and I want a function to take a part of data for processing only. It will only read and won't change. char[] importantData; With Immutable, void dataProcessor( string giveMeAllYourData ){} dataProcessor( cast( immutable )( importantData[5 .. 14] ) ); With Const, vo

Re: Is this possible in D?

2015-02-19 Thread tcak via Digitalmars-d-learn
On Thursday, 19 February 2015 at 12:16:18 UTC, Mike Parker wrote: On Thursday, 19 February 2015 at 10:17:47 UTC, Dicebot wrote: Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version): I really like mixins for this sort of thing. ``` en

Re: Is this possible in D?

2015-02-19 Thread tcak via Digitalmars-d-learn
On Thursday, 19 February 2015 at 08:24:08 UTC, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void m

Re: dmd-2.067.0-b1

2015-02-13 Thread tcak via Digitalmars-d-learn
On Friday, 13 February 2015 at 09:38:04 UTC, Dennis Ritchie wrote: This is a bug? import std.stdio; void main() { int a = 0; writeln( (a < 10) ? a = 1 : a = 2 );// prints 2 writeln( (a < 10) ? a = 1 : (a = 2) ); // prints 1 } Even C++ output: 1 1 About 2 years ago, I had a

Re: Is there an object on given memory address?

2015-02-12 Thread tcak via Digitalmars-d-learn
Or send a hash of the object along with the memory address, then query the GC wether the memory is still allocated. This part sounds interesnting. How does that GC querying thing works exactly?

Re: Is there an object on given memory address?

2015-02-12 Thread tcak via Digitalmars-d-learn
On Thursday, 12 February 2015 at 10:03:18 UTC, tcak wrote: Is there any "reliable" way to determine whether there is a certain type of object in memory at a given address? I am going to send the memory address of an object to another program over pipes. Then after a while, other program will s

Is there an object on given memory address?

2015-02-12 Thread tcak via Digitalmars-d-learn
Is there any "reliable" way to determine whether there is a certain type of object in memory at a given address? I am going to send the memory address of an object to another program over pipes. Then after a while, other program will send that memory address, and main program will try to addre

Fast array copy. SIMD manual or automatic?

2015-02-06 Thread tcak via Digitalmars-d-learn
I have two char arrays at the size of 16KB. I will copy a part of data between them again and again. arrayA[0 .. dataLen] = arrayB[0 .. dataLen]; Does the compiler generate code that uses SIMD operations (128-bits memory copy) automatically, or do I need to do anything special for this?

Re: Arrays of Unions of Classes?

2015-02-06 Thread tcak via Digitalmars-d-learn
On Friday, 6 February 2015 at 18:55:30 UTC, DLearner wrote: I'm just wondering how I would go about reserving a section of the heap so I can have linear access to classes of different types. Storage space--not too worried about wasting; each class I want to store only has a few int sized variabl

Re: Wrong pointer calculation without casting on struct

2015-02-05 Thread tcak via Digitalmars-d-learn
On Friday, 6 February 2015 at 03:59:51 UTC, tcak wrote: I am on 64-bit Linux. I defined a struct that it 8 bytes in total. align(1) struct MessageBase{ align(1): ushort qc; ushort wc; ushort id; ushort contentLength; void[0] content; } I defined a funct

Wrong pointer calculation without casting on struct

2015-02-05 Thread tcak via Digitalmars-d-learn
I am on 64-bit Linux. I defined a struct that it 8 bytes in total. align(1) struct MessageBase{ align(1): ushort qc; ushort wc; ushort id; ushort contentLength; void[0] content; } I defined a function in this struct that tries to set a pointer to "conte

Re: Labels in struct

2015-01-31 Thread tcak via Digitalmars-d-learn
On Saturday, 31 January 2015 at 16:04:36 UTC, tcak wrote: I do not have a big example in the end to show, but is there any way to put labels into struct definitions? struct CommunicationMessage{ char[2] signature; mainData: int info1; int info2; extraData: ushort checksum; co

Labels in struct

2015-01-31 Thread tcak via Digitalmars-d-learn
I do not have a big example in the end to show, but is there any way to put labels into struct definitions? struct CommunicationMessage{ char[2] signature; mainData: int info1; int info2; extraData: ushort checksum; content: } Example I defined something like above. I am usi

Re: Import paths do not work

2015-01-29 Thread tcak via Digitalmars-d-learn
On Thursday, 29 January 2015 at 10:26:56 UTC, Atila Neves wrote: I would suggest instead of using make, use dub[0] build manager instead. It'll handle grabbing all the files and compiling them correctly. [0] http://code.dlang.org/package-format Or for simple projects such as this one seems t

Import paths do not work

2015-01-28 Thread tcak via Digitalmars-d-learn
I have a library that has many folders and D files in them. I do not want to list name of all module files one by one while compiling projects. So, I thought I could use "-I" flag while compiling. It says: -Ipath where to look for imports So, I made a test as follows: ./test.d =

Re: Turning Executable into Application?

2015-01-25 Thread tcak via Digitalmars-d-learn
On Monday, 26 January 2015 at 03:36:32 UTC, Gan wrote: With Xamarin Studio I create a D project and run it. It runs an Executable Unix file through the terminal. How can I turn that into an Application that doesn't open the Terminal? Thanks. I use MonoDevelop. I haven't tried that but in Pro

Overloaded function disappears on polymorphism

2015-01-24 Thread tcak via Digitalmars-d-learn
main.d === class Car{ public void makeBeep( char c ){} public void makeBeep( string s ){} } class Tesla: Car{ override public void makeBeep( char c ){ writeln("C = ", c); } } void main(){ auto

Run only "unittest", skip "main"

2015-01-24 Thread tcak via Digitalmars-d-learn
Is there any way to run only unittest codes, and ignore main function? DMD is running both of them when I use -unittest.

Re: Defining a static array with values in a range

2015-01-22 Thread tcak via Digitalmars-d-learn
On Thursday, 22 January 2015 at 17:15:34 UTC, Jonathan M Davis via Digitalmars-d-learn wrote: On Thursday, January 22, 2015 15:16:07 bearophile via Digitalmars-d-learn wrote: Jonathan M Davis: > but that's easy fixed with some +1's. But the +1 changes the char to an int. True, though iota do

Re: Defining a static array with values in a range

2015-01-22 Thread tcak via Digitalmars-d-learn
On Thursday, 22 January 2015 at 07:29:05 UTC, anony wrote: On Thursday, 22 January 2015 at 05:56:40 UTC, tcak wrote: I want to define alphanumeric characters in an easy way. Something like that: char[] arr = ['a'..'z', 'A'..'Z', '0'..'9']; Though above example doesn't work. Is there any easy

Defining a static array with values in a range

2015-01-21 Thread tcak via Digitalmars-d-learn
I want to define alphanumeric characters in an easy way. Something like that: char[] arr = ['a'..'z', 'A'..'Z', '0'..'9']; Though above example doesn't work. Is there any easy way to do this? I am trying to do something like EBNF definitions. So, I do not want to use loops, or define every

Undefined reference error when array size is given

2015-01-19 Thread tcak via Digitalmars-d-learn
Code is as follows: main.d = import core.sys.posix.poll; void main(){ core.sys.posix.poll.pollfd[2] pollList; } = Error: main.d:(.text._Dmain+0x15): undefined reference to `_D4core3sys5posix4poll6pollfd6__initZ' Remove "2" and it work

Re: Bug on Posix IPC_STAT. Wrong number of attachments

2015-01-18 Thread tcak via Digitalmars-d-learn
On Monday, 19 January 2015 at 04:18:47 UTC, tcak wrote: On Sunday, 18 January 2015 at 22:25:39 UTC, anonymous wrote: On Sunday, 18 January 2015 at 18:07:05 UTC, tcak wrote: After these, it works perfectly. I hope this can be fixed in next version. Please file a bug at

Re: Bug on Posix IPC_STAT. Wrong number of attachments

2015-01-18 Thread tcak via Digitalmars-d-learn
On Sunday, 18 January 2015 at 22:25:39 UTC, anonymous wrote: On Sunday, 18 January 2015 at 18:07:05 UTC, tcak wrote: After these, it works perfectly. I hope this can be fixed in next version. Please file a bug at . And since you seem to know how to fix it, maybe you

Re: Bug on Posix IPC_STAT. Wrong number of attachments

2015-01-18 Thread tcak via Digitalmars-d-learn
On Sunday, 18 January 2015 at 16:06:39 UTC, tcak wrote: I create a shared memory by using shmget. And attach to it by using shmat. Finally, I use shmctl to get statistics to learn number of attachments to that shared memory. According to documentation (linux.die.net/man/2/shmat), number of at

Bug on Posix IPC_STAT. Wrong number of attachments

2015-01-18 Thread tcak via Digitalmars-d-learn
I create a shared memory by using shmget. And attach to it by using shmat. Finally, I use shmctl to get statistics to learn number of attachments to that shared memory. According to documentation (linux.die.net/man/2/shmat), number of attachments should be 1. Same codes, C returns 1, D retur

Re: Endless static this call when used a thread in it

2015-01-13 Thread tcak via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 13:53:11 UTC, tcak wrote: I have written the following code: test.d == import core.thread; import std.stdio; void threadFunc(){ writeln("Thread func"); } public static this(){ auto t = new Thread( &threadFunc );

Endless static this call when used a thread in it

2015-01-13 Thread tcak via Digitalmars-d-learn
I have written the following code: test.d == import core.thread; import std.stdio; void threadFunc(){ writeln("Thread func"); } public static this(){ auto t = new Thread( &threadFunc ); t.start(); writeln("Static init"); } void main(

Re: Accessing class with module name as Java's

2015-01-13 Thread tcak via Digitalmars-d-learn
Ah, I just re-read your OP. Your already at this point :) Since everybody has understood the problem, and nobody could have come up with a solution yet, my idea is that: HttpSocketConnectionRequest.d = module net.http.HttpSocketConnectionRequest; module c

Re: Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
On Tuesday, 13 January 2015 at 05:18:46 UTC, Ali Çehreli wrote: On 01/12/2015 08:22 PM, tcak wrote: >> What namespace? D has modules, unlike C++. In general it's a bad idea >> to have inside a module a name (like a variable name or struct name) >> equal to the module name, because it causes confu

Re: Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
What namespace? D has modules, unlike C++. In general it's a bad idea to have inside a module a name (like a variable name or struct name) equal to the module name, because it causes confusion. I am confused as well. core.stdc.errno @property int errno() { return getErrno(); } @property int

Re: Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
On Monday, 12 January 2015 at 18:11:35 UTC, bearophile wrote: D modules can contain lot of stuff, like variables, constants, enums, types, structs, etc. And you usually put more than one class in each D module. Also D class names should be capitalized (like "Project"). When I do this, it w

Accessing class with module name as Java's

2015-01-12 Thread tcak via Digitalmars-d-learn
In java, if I create a file, the class that is defined in it must have the same name of file. So, with the file name, I can relate to class directly. Is there any way to achieve this in D? One way I achieved it, though I cannot put namespace on it. file: project.d == module pr

Re: On inheritance and polymorphism in cats and dogs (and other beasts too)

2014-12-20 Thread tcak via Digitalmars-d-learn
On Saturday, 20 December 2014 at 15:40:32 UTC, Derix wrote: So, I have this pet project where classes Cat and Dog inherit from the more generic Beast class. All beasts prosper and multiply and so do cats and dogs. The breeding routine is fairly constant across species, with minor variations. So

Re: Compiling with SQLite

2014-11-18 Thread tcak via Digitalmars-d-learn
On Tuesday, 18 November 2014 at 05:06:59 UTC, impatient-dev wrote: On Tuesday, 18 November 2014 at 03:41:42 UTC, uri wrote: Are you linking with libsqlite3.a? For example: $ dmd prog.d -L-lsqlite3 That worked, thanks. I didn't know you had to anything special to link with code in the standa

Re: Cast to left hand side

2014-11-09 Thread tcak via Digitalmars-d-learn
On Sunday, 9 November 2014 at 21:47:03 UTC, eles wrote: On Sunday, 9 November 2014 at 19:00:01 UTC, tcak wrote: I am also strongly in favor of introducing an "uncast". For example, in C++'x const_cast and in D's cast for removing, for example immutability: immutable int* p = ...; int* q = ca

Cast to left hand side

2014-11-09 Thread tcak via Digitalmars-d-learn
In some cases, I need to cast right hand side expression to left hand side. While it looks/feels simple for basic data types, it requires long lines with duplication when flexible code is desired to be written. Example: int a = 7; byte b; b = cast( byte )a; When I want to create a system w

libphobos2.so insists on its name while using shared libraries

2014-11-08 Thread tcak via Digitalmars-d-learn
I am using DMD 2.066.1 on Ubuntu 14.04 64-bit. I used the latest main.d and dll.d codes from http://dlang.org/dll-linux.html Then I used the following make file: all: cp /usr/lib/x86_64-linux-gnu/libphobos2.so ./libmyphobos2.so dmd -c dll.d -fPIC dmd -oflibdll.so dll.o -shar

Re: new(malloc) locks everything in multithreading

2014-10-24 Thread tcak via Digitalmars-d-learn
On Friday, 24 October 2014 at 21:02:05 UTC, Kapps wrote: On Friday, 24 October 2014 at 18:38:39 UTC, tcak wrote: On Friday, 24 October 2014 at 16:51:02 UTC, Kapps wrote: This is what I did on shell: (I put some spaces for readability) tolga@tolga:~/dev/d/bug$ dmd -gc -debug test.d tolga@tol

<    1   2   3   >