Struct Union behavior

2016-01-06 Thread Voitech via Digitalmars-d-learn
Hello, i am new to D language and trying to learn it by coding. I compile my programs on Xubuntu 14.04 with DMD64 D Compiler v2.069.2. So i have a struct/union which contains two fields representing real and string values: public union Element { private real _value; private

Re: GTKD Cairo get pixel color

2016-01-06 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 01:41:03 UTC, Basile B. wrote: Until a certain "time" my answers were useful. But I recognize that after this "time" I've managed to turn the topic into something totally delirious because, to be honest I was completly sratched by alcohool. I'm sorry but life is

Re: noob in c macro preprocessor hell converting gsl library header files

2016-01-06 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 13:36:03 UTC, data pulverizer wrote: I have been converting C numeric libraries and depositing them here: https://github.com/dataPulverizer. So far I have glpk and nlopt converted on a like for like c function basics. I am now stuck on the gsl library, primarily

Nothrow front() when not empty()

2016-01-06 Thread Nordlöw via Digitalmars-d-learn
At https://github.com/D-Programming-Language/phobos/pull/3752 it would be nice if return !haystack.empty && haystack.front.unaryFun!pred was made nothrow. Is this possible somehow?

Re: Struct Union behavior

2016-01-06 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 11:39:44 UTC, Voitech wrote: Hello, i am new to D language and trying to learn it by coding. I compile my programs on Xubuntu 14.04 with DMD64 D Compiler v2.069.2. So i have a struct/union which contains two fields representing real and string values: public

Re: Struct Union behavior

2016-01-06 Thread Voitech via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 12:25:31 UTC, Nicholas Wilson wrote: Probably because you are accessing uninitialised memory. the values 4,5,9 appear in the first unittest and are left on the stack. Unions ,unlike structs, do not initialise their fields because it does not make sense to do so

Re: Nothrow front() when not empty()

2016-01-06 Thread anonymous via Digitalmars-d-learn
On 06.01.2016 14:52, Nordlöw wrote: At https://github.com/D-Programming-Language/phobos/pull/3752 it would be nice if return !haystack.empty && haystack.front.unaryFun!pred was made nothrow. Is this possible somehow? try return !haystack.empty && pred(haystack.front); catch

noob in c macro preprocessor hell converting gsl library header files

2016-01-06 Thread data pulverizer via Digitalmars-d-learn
I have been converting C numeric libraries and depositing them here: https://github.com/dataPulverizer. So far I have glpk and nlopt converted on a like for like c function basics. I am now stuck on the gsl library, primarily because of the preprocessor c code which I am very new to. The

Re: link to C function whose name is a D keyword

2016-01-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 15:41:27 UTC, Carl Sturtivant wrote: //D that doesn't work: extern(C) int try(int x); Try: pragma(mangle, "try") extern(C) int try_(int x); then call it with the udnerscore in D, the linker should tie it up thanks to the pragma.

Re: noob in c macro preprocessor hell converting gsl library header files

2016-01-06 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 13:59:44 UTC, John Colvin wrote: #define INLINE_FUN extern inline // used in gsl_pow_int.h: INLINE_FUN double gsl_pow_2(const double x) { return x*x; } Could I just ignore the INLINE_FUN and use alias for function pointer declaration? For example ... alias

Re: link to C function whose name is a D keyword

2016-01-06 Thread Carl Sturtivant via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 15:42:34 UTC, Adam D. Ruppe wrote: On Wednesday, 6 January 2016 at 15:41:27 UTC, Carl Sturtivant wrote: //D that doesn't work: extern(C) int try(int x); Try: pragma(mangle, "try") extern(C) int try_(int x); then call it with the udnerscore in D, the linker

link to C function whose name is a D keyword

2016-01-06 Thread Carl Sturtivant via Digitalmars-d-learn
Hello, Is there a way from D to do this, without writing a C wrapper? e.g. I want to call a C function named 'try'. /* C prototype */ int try(int x); //D that doesn't work: extern(C) int try(int x);

Custom type creation guidelines

2016-01-06 Thread rumbu via Digitalmars-d-learn
Let's suppose that I want to implement a custom arithmetic type. Looking through phobos at Complex, BigInt, HalfFloat, Variant, etc, there is no consistent or idiomatic way to implement various operators or functions on custom types. 1) Regarding unary operator overloading, what's the best

link to C++ function in a namespace whose name is a D keyword

2016-01-06 Thread Carl Sturtivant via Digitalmars-d-learn
Hello, From D I want to call e.g. /* C++ prototype */ namespace ns { int try(int x); } without writing a C or C++ wrapper. Presumably the following D doesn't work, because it doesn't mangle the name as if it's in the namespace ns. pragma(mangle, "try") extern(C++, ns) int try_(int x);

Re: link to C++ function in a namespace whose name is a D keyword

2016-01-06 Thread Ali Çehreli via Digitalmars-d-learn
On 01/06/2016 10:35 AM, Carl Sturtivant wrote: Hello, From D I want to call e.g. /* C++ prototype */ namespace ns { int try(int x); } without writing a C or C++ wrapper. Presumably the following D doesn't work, because it doesn't mangle the name as if it's in the namespace ns.

Type properties

2016-01-06 Thread ric maicle via Digitalmars-d-learn
Why is init allowed to be redefined but not sizeof? dmd 2.069 import std.stdio; struct Foo { static int init = 5; static int sizeof = 0; } void main() { writeln(Foo.init); writeln(Foo.sizeof); } Error: variable integer.Foo.sizeof .sizeof property cannot be redefined

Re: Type properties

2016-01-06 Thread ric maicle via Digitalmars-d-learn
On Wednesday, 06 January, 2016 04:01 PM, ric maicle wrote: Why is init allowed to be redefined but not sizeof? dmd 2.069 import std.stdio; struct Foo { static int init = 5; static int sizeof = 0; } void main() { writeln(Foo.init); writeln(Foo.sizeof); } Error: variable

Calling functions from other files/modules

2016-01-06 Thread Namal via Digitalmars-d-learn
Hello, finally I want to learn how to do it right and I tried to understand it from here https://en.wikibooks.org/wiki/D_(The_Programming_Language)/d2/Modules But I have a few questions. Do I have always to include std.stdio in every file like in the example or is it enough just to import

Re: Calling functions from other files/modules

2016-01-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 22:06:32 UTC, Namal wrote: Do I have always to include std.stdio in every file like in the example or is it enough just to import a module which has this already included? In every file that you use it, yes. Module imports are private to the module (well,

Re: String interpolation

2016-01-06 Thread cym13 via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 23:30:22 UTC, Guillaume Piolat wrote: Is there a fancy way to have some kind of string interpolation in D? Other than std.format.format that is?

Re: About Immutable struct members and arrays.

2016-01-06 Thread anonymous via Digitalmars-d-learn
On 06.01.2016 23:04, Jack Applegame wrote: import std.algorithm; struct Bar { const int a; int b; } void main() { Bar[1] arr; Bar bar = Bar(1, 2); bar[0].b = 4; Assuming you meant `arr[0].b = 4;`. Just overwriting the mutable part of bar[0] is ok, of course.

About Immutable struct members and arrays.

2016-01-06 Thread Jack Applegame via Digitalmars-d-learn
import std.algorithm; struct Bar { const int a; int b; } void main() { Bar[1] arr; Bar bar = Bar(1, 2); bar[0].b = 4; move(bar, arr[0]); // ok arr[1] = bar;// fail, why? move(Bar(1, 2), arr[0]); // fail, why source parameter isn't auto ref? }

String interpolation

2016-01-06 Thread Guillaume Piolat via Digitalmars-d-learn
Is there a fancy way to have some kind of string interpolation in D?

Re: Calling functions from other files/modules

2016-01-06 Thread Namal via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 22:15:43 UTC, Adam D. Ruppe wrote: You can import it as long as you define it! I just tried to import one module with a main into another, but I get this: Error: only one main allowed

Re: SIGSEGV in invariant._d_invariant(Object)

2016-01-06 Thread Keywan Ghadami via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 21:58:51 UTC, Adam D. Ruppe wrote: On Wednesday, 6 January 2016 at 21:50:23 UTC, Keywan Ghadami wrote: how to fix an SIGSEGV in invariant._d_invariant(Object)? That means you are calling a method on a null object. Your object might be at the bottom of the

Re: Calling functions from other files/modules

2016-01-06 Thread Namal via Digitalmars-d-learn
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 you can import a module with main from another module

Re: String interpolation

2016-01-06 Thread Meta via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 23:30:22 UTC, Guillaume Piolat wrote: Is there a fancy way to have some kind of string interpolation in D? This is probably the best you're going to be able to do in D in regards to string interpolation.

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: SIGSEGV in invariant._d_invariant(Object)

2016-01-06 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 21:50:23 UTC, Keywan Ghadami wrote: how to fix an SIGSEGV in invariant._d_invariant(Object)? That means you are calling a method on a null object. Your object might be at the bottom of the stack trace listing. Check your code for a declared class that you

Re: Calling functions from other files/modules

2016-01-06 Thread Adam D. Ruppe via Digitalmars-d-learn
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 you can import a module with main from another module without one.

Re: Nothrow front() when not empty()

2016-01-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 14:17:51 UTC, anonymous wrote: try return !haystack.empty && pred(haystack.front); Might want to use std.exception.assumeWontThrow instead return assumeWontThrow(!haystack.empty && pred(haystack.front));

Re: link to C++ function in a namespace whose name is a D keyword

2016-01-06 Thread Alex Parrill via Digitalmars-d-learn
On Wednesday, 6 January 2016 at 18:35:07 UTC, Carl Sturtivant wrote: Hello, From D I want to call e.g. /* C++ prototype */ namespace ns { int try(int x); } without writing a C or C++ wrapper. Presumably the following D doesn't work, because it doesn't mangle the name as if it's in the

Re: link to C++ function in a namespace whose name is a D keyword

2016-01-06 Thread Jacob Carlborg via Digitalmars-d-learn
On 2016-01-06 19:35, Carl Sturtivant wrote: Hello, From D I want to call e.g. /* C++ prototype */ namespace ns { int try(int x); } without writing a C or C++ wrapper. Presumably the following D doesn't work, because it doesn't mangle the name as if it's in the namespace ns.

Re: Get superclasses at compile time

2016-01-06 Thread Straivers via Digitalmars-d-learn
Huh, alright. Thanks.

SIGSEGV in invariant._d_invariant(Object)

2016-01-06 Thread Keywan Ghadami via Digitalmars-d-learn
Hi @all, how to fix an SIGSEGV in invariant._d_invariant(Object)? Maybe i should give some context: I am learning D and started hacking the dlangide(https://github.com/buggins/dlangide), and normally finding the cause of an segmentation fault isn't that hard. But this time it is somehow