'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread nikki via Digitalmars-d-learn
I am learning SDL by following the lazyfoo SDL2 tuorials, I am alos new to D so I have a question: I the lazyfoo tutorials there are many functions that have a bool success whiich gets set at various places when something goes wrong to be returned afterwards. http://lazyfoo.net/tutorials/SDL

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 10:19:58 + nikki via Digitalmars-d-learn wrote: don't use '==' to check for nulls. the right way is: if (foo is null) {} if (bar !is null) {} '==' transforms to opEquals call (see 'operator overloading') and 'is' not. as for 'best practice' question -- it depends of

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread nikki via Digitalmars-d-learn
Oops well writing the above post made me realise what to look for : http://dlang.org/errors.html ;)

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread nikki via Digitalmars-d-learn
On Saturday, 23 August 2014 at 10:29:04 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 23 Aug 2014 10:19:58 + nikki via Digitalmars-d-learn wrote: don't use '==' to check for nulls. the right way is: if (foo is null) {} if (bar !is null) {} '==' transforms to opEquals call (see

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread bearophile via Digitalmars-d-learn
nikki: How would you write it? I don't know how much idiomatic this is, but you can start cleaning up the code: - Renaming the function with something more clear; - using a D enumeration for the various constants. - I have used a "." before the module-level variables to denote better they a

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread bearophile via Digitalmars-d-learn
ketmar: don't use '==' to check for nulls. the right way is: if (foo is null) {} if (bar !is null) {} '==' transforms to opEquals call (see 'operator overloading') and 'is' not. I use "is" and "!is" for class references and == != for pointers. But now I think you are right, and in D it

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 10:53:03 + bearophile via Digitalmars-d-learn wrote: > I use "is" and "!is" for class references and == != for pointers. > But now I think you are right, and in D it's better to always use > is and !is for both, to avoid present and future bugs (like when > a pointer ge

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread hane via Digitalmars-d-learn
On Saturday, 23 August 2014 at 10:19:59 UTC, nikki wrote: I am learning SDL by following the lazyfoo SDL2 tuorials, I am alos new to D so I have a question: I the lazyfoo tutorials there are many functions that have a bool success whiich gets set at various places when something goes wrong to

Acces Values in DList

2014-08-23 Thread axwro via Digitalmars-d-learn
How can i access values in DList? I save different objects of type "Property" in my DList, but if i want to access them this way: this.properties[0].value.start i get: Error: no [] operator overload for type DList!(Property)

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 23 August 2014 at 10:33:02 UTC, nikki wrote: A good to know! thanks. I'd still be interrested to see the idiomatic D version of that function, what would that depend on ? Honestly, I wouldn't change it much. If it didn't throw exceptions before, then it probably would have troubl

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread Kagamin via Digitalmars-d-learn
On Saturday, 23 August 2014 at 11:07:23 UTC, ketmar via Digitalmars-d-learn wrote: and "foo is null" is nice to read. ;-) Meh, looks like a guest from pascal or basic.

Re: Acces Values in DList

2014-08-23 Thread axwro via Digitalmars-d-learn
On Saturday, 23 August 2014 at 14:54:55 UTC, axwro wrote: How can i access values in DList? I save different objects of type "Property" in my DList, but if i want to access them this way: this.properties[0].value.start i get: Error: no [] operator overload for type DList!(Property)

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 15:10:22 + Kagamin via Digitalmars-d-learn wrote: > Meh, looks like a guest from pascal or basic. so let's replace writeln() with %&^#$#%^& then. this looks like a function name for Real Hackers. signature.asc Description: PGP signature

Re: 'idiomatic' porting of c and or c++ code that does NULL checking

2014-08-23 Thread Kagamin via Digitalmars-d-learn
On Saturday, 23 August 2014 at 11:07:23 UTC, ketmar via Digitalmars-d-learn wrote: and "foo is null" is nice to read. ;-) function bool init begin rem Initialization flag bool success assign true; rem Initialize SDL if execute SDL_Init SDL_INIT_VIDEO lt 0 begin exec

Module-level attributes and unit tests

2014-08-23 Thread Leandro Motta Barros via Digitalmars-d-learn
Hello, I have a module which is completelly @nogc, and as such I'd like to just say @nogc: at the top of the file and be happy. However, my unit tests for this same module do some GC allocation, so the module fails to compile. Is there a way to disable @nogc for the unit tests only? Would t

Re: Acces Values in DList

2014-08-23 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 23 August 2014 at 15:18:15 UTC, axwro wrote: On Saturday, 23 August 2014 at 14:54:55 UTC, axwro wrote: How can i access values in DList? I save different objects of type "Property" in my DList, but if i want to access them this way: this.properties[0].value.start i get: Error:

Re: Module-level attributes and unit tests

2014-08-23 Thread monarch_dodra via Digitalmars-d-learn
On Saturday, 23 August 2014 at 15:26:02 UTC, Leandro Motta Barros via Digitalmars-d-learn wrote: Hello, I have a module which is completelly @nogc, and as such I'd like to just say @nogc: at the top of the file and be happy. However, my unit tests for this same module do some GC allocat

Is this RDMD bug ?

2014-08-23 Thread novice2 via Digitalmars-d-learn
I have 2 reduced files, wich i can't compile with new (DMD 2.066) rdmd.exe under Windows 7 32-bit. Command: rdmd --force --build-only aaa.d Message "Error 42: Symbol Undefined _D3etc3bbb3fooFZi" But command: dmd aaa.d etc\bbb.d Compile without errors. And then i replace rdmd.exe by old (from DM

Re: Module-level attributes and unit tests

2014-08-23 Thread Leandro Motta Barros via Digitalmars-d-learn
Thanks, this was helpful! LMB On Sat, Aug 23, 2014 at 1:22 PM, monarch_dodra via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Saturday, 23 August 2014 at 15:26:02 UTC, Leandro Motta Barros via > Digitalmars-d-learn wrote: > >> Hello, >> >> I have a module which is comple

Re: Is this RDMD bug ?

2014-08-23 Thread sigod via Digitalmars-d-learn
On Saturday, 23 August 2014 at 16:28:46 UTC, novice2 wrote: I have 2 reduced files, wich i can't compile with new (DMD 2.066) rdmd.exe under Windows 7 32-bit. Command: rdmd --force --build-only aaa.d Message "Error 42: Symbol Undefined _D3etc3bbb3fooFZi" But command: dmd aaa.d etc\bbb.d Compil

Re: Iterating over the tupleof of a struct

2014-08-23 Thread Meta via Digitalmars-d-learn
On Saturday, 23 August 2014 at 01:56:06 UTC, Dicebot wrote: On Saturday, 23 August 2014 at 01:32:13 UTC, Meta wrote: On Saturday, 23 August 2014 at 01:24:10 UTC, Meta wrote: What is happening here? Are these two extra ulongs the offsets of the fields in the struct? And I just realized that th

Re: Is this RDMD bug ?

2014-08-23 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 23 August 2014 at 16:28:46 UTC, novice2 wrote: I have 2 reduced files, wich i can't compile with new (DMD 2.066) rdmd.exe under Windows 7 32-bit. Command: rdmd --force --build-only aaa.d Message "Error 42: Symbol Undefined _D3etc3bbb3fooFZi" But command: dmd aaa.d etc\bbb.d Compil

Re: Is this RDMD bug ?

2014-08-23 Thread sigod via Digitalmars-d-learn
PR that introduced regression: https://github.com/D-Programming-Language/tools/pull/108

Re: Is this RDMD bug ?

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 16:28:46 UTC, novice2 wrote: I have 2 reduced files, wich i can't compile with new (DMD 2.066) rdmd.exe under Windows 7 32-bit. Command: rdmd --force --build-only aaa.d Message "Error 42: Symbol Undefined _D3etc3bbb3fooFZi" But command: dmd aaa.d etc\bbb.d Compil

Re: Is this RDMD bug ?

2014-08-23 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:29:15 UTC, sigod wrote: PR that introduced regression: https://github.com/D-Programming-Language/tools/pull/108 Filed: https://issues.dlang.org/show_bug.cgi?id=13366

Re: Is this RDMD bug ?

2014-08-23 Thread sigod via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: No, it is not an rdmd bug. "etc" is a standard D package name reserved for Phobos, the standard library. It is the same for "std" and "core". Please, point us directly to a documentation where it says that this words rese

-inline switch changes code behaviour

2014-08-23 Thread francesco cattoglio via Digitalmars-d-learn
Today I just realized that in DMD optimize flag does not imply inlining, therefore I promptly added the "inline" to my dub build settings and recompiler, expecting to see speedups in my code execution. To my surprise, I could not see anything at all: all that I get now is a blank screen. The

Re: Is this RDMD bug ?

2014-08-23 Thread Dicebot via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:37:39 UTC, sigod wrote: On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: No, it is not an rdmd bug. "etc" is a standard D package name reserved for Phobos, the standard library. It is the same for "std" and "core". Please, point us dire

Re: Is this RDMD bug ?

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:37:39 UTC, sigod wrote: On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: No, it is not an rdmd bug. "etc" is a standard D package name reserved for Phobos, the standard library. It is the same for "std" and "core". Please, point us dire

D1: Error: duplicate union initialization for size

2014-08-23 Thread jicman via Digitalmars-d-learn
Greetings. I know that D1 will be deprecated pretty soon and I have a huge project based on D1. I am trying to build everything using the latest D1 build (1.076). I am looking into cleaning up a lot of code for this project that uses, dbi, juno and dfl. I am finding this error while compi

Re: -inline switch changes code behaviour

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:44:41 UTC, francesco cattoglio wrote: any suggestion on how to debug this? If you can write a script which can compare the behavior of two builds of your program to return 0 if they differ or 1 if they are identical, you could plug it into DustMite. Write a t

Re: Is this RDMD bug ?

2014-08-23 Thread novice2 via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: "etc" is a standard D package name reserved for Phobos, the Thanks for explanation. I not be able to undertsand the cause - weird error message. Now i can easy fix my code. BTW, did rdmd determine user code or standard libr

Re: Is this RDMD bug ?

2014-08-23 Thread sigod via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:41:38 UTC, Dicebot wrote: On Saturday, 23 August 2014 at 17:37:39 UTC, sigod wrote: On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: No, it is not an rdmd bug. "etc" is a standard D package name reserved for Phobos, the standard library.

Re: Is this RDMD bug ?

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 18:23:25 UTC, sigod wrote: Actually, I never got to use this names for first package name. (I only used `.etc` and `.core`.) So, I didn't thought about this. `.etc` and `.core` should work fine. Only the three top-level package names are reserved by rdmd for Ph

Re: Is this RDMD bug ?

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 18:23:25 UTC, sigod wrote: Isn't it better to document such things? Yes. Please create a pull request.

Re: Is this RDMD bug ?

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 18:12:44 UTC, novice2 wrote: On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: "etc" is a standard D package name reserved for Phobos, the Thanks for explanation. I not be able to undertsand the cause - weird error message. Now i can easy fix

Re: Is this RDMD bug ?

2014-08-23 Thread via Digitalmars-d-learn
On Saturday, 23 August 2014 at 17:41:38 UTC, Dicebot wrote: On Saturday, 23 August 2014 at 17:37:39 UTC, sigod wrote: On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: No, it is not an rdmd bug. "etc" is a standard D package name reserved for Phobos, the standard library.

Re: Is this RDMD bug ?

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 18:41:58 UTC, Marc Schütz wrote: On Saturday, 23 August 2014 at 17:41:38 UTC, Dicebot wrote: On Saturday, 23 August 2014 at 17:37:39 UTC, sigod wrote: On Saturday, 23 August 2014 at 17:32:15 UTC, Vladimir Panteleev wrote: No, it is not an rdmd bug. "etc" is a st

Re: Is this RDMD bug ?

2014-08-23 Thread sigod via Digitalmars-d-learn
On Saturday, 23 August 2014 at 18:28:32 UTC, Vladimir Panteleev wrote: On Saturday, 23 August 2014 at 18:23:25 UTC, sigod wrote: Isn't it better to document such things? Yes. Please create a pull request. Easy to say. In my TODO list lies record to create PR for [this issue][0]. Today is ex

Re: Is this RDMD bug ?

2014-08-23 Thread via Digitalmars-d-learn
On Saturday, 23 August 2014 at 18:43:35 UTC, Vladimir Panteleev wrote: On Saturday, 23 August 2014 at 18:41:58 UTC, Marc Schütz wrote: On Saturday, 23 August 2014 at 17:41:38 UTC, Dicebot wrote: On Saturday, 23 August 2014 at 17:37:39 UTC, sigod wrote: On Saturday, 23 August 2014 at 17:32:15 UT

Re: Is this RDMD bug ?

2014-08-23 Thread Vladimir Panteleev via Digitalmars-d-learn
On Saturday, 23 August 2014 at 18:55:08 UTC, Marc Schütz wrote: But imported modules are the important case. If I have an important bugfix in a module, and don't want to wait for the next release, what am I supposed to do? Rebuild Phobos. If rdmd were to compile your module, linking would fai

Re: Iterating over the tupleof of a struct

2014-08-23 Thread Ali Çehreli via Digitalmars-d-learn
On 08/23/2014 10:21 AM, Meta wrote: On Saturday, 23 August 2014 at 01:56:06 UTC, Dicebot wrote: On Saturday, 23 August 2014 at 01:32:13 UTC, Meta wrote: On Saturday, 23 August 2014 at 01:24:10 UTC, Meta wrote: What is happening here? Are these two extra ulongs the offsets of the fields in the

Re: Iterating over the tupleof of a struct

2014-08-23 Thread Meta via Digitalmars-d-learn
On Saturday, 23 August 2014 at 20:34:35 UTC, Ali Çehreli wrote: There are a number of inconsistencies around tuples. The behavior you expect is present for ranges that return tuple fronts: import std.stdio; import std.typecons; import std.range; void main() { auto t = [ tuple(1.5, 100), t

Binary Dscanner Releases

2014-08-23 Thread Nordlöw
Will there be any binary releases of Dscanner? I'm wondering because the maintainer of FlyCheck needs this for official FlyCheck support for Dscanner. For details see: https://github.com/flycheck/flycheck/pull/426

Re: Compile-Time Value Trait

2014-08-23 Thread Nordlöw
On Saturday, 23 August 2014 at 22:12:06 UTC, Nordlöw wrote: I'm looking for a trait, say isCTExpression, that can check I just say http://forum.dlang.org/thread/mailman.1953.1373509028.13711.digitalmar...@puremagic.com Is this still the preferred way to do it?

Compile-Time Value Trait

2014-08-23 Thread Nordlöw
I'm looking for a trait, say isCTExpression, that can check whether an alias parameter is an expression evaluable during compile-time? Have anybody written such a thing?

Re: Compile-Time Value Trait

2014-08-23 Thread Nordlöw
On Saturday, 23 August 2014 at 22:14:34 UTC, Nordlöw wrote: On Saturday, 23 August 2014 at 22:12:06 UTC, Nordlöw wrote: As a complement I came up with /** Check if the value of $(D expr) is known at compile-time. See also: http://forum.dlang.org/thread/owlwzvidwwpsrelpk...@forum.dlang.org

Large binary size using std.regex

2014-08-23 Thread Bayan Rafeh via Digitalmars-d-learn
Compiling a simple program using std.regex: import std.regex; import std.stdio; void main(string[] args) { auto re = regex(args[1], "g"); foreach(line; stdin.byLine) if(line.match(re)) writeln(line); } Renders a 1.6 megabyte binary. Is that normal?

how to tell if a thing is a template

2014-08-23 Thread Ellery Newcomer via Digitalmars-d-learn
Can't think off the top of my head how you do this template IsTemplate(alias t) { ?? } static assert(IsTemplate!IsTemplate)

Error: template cannot deduce function from argument types.

2014-08-23 Thread Damian Day via Digitalmars-d-learn
Hi, I've been trying to reduce a bug in the containers (8824). From the example below it seems the dup method is passing the constructor an array of dchars and the template is failing. Is this a compiler bug, or ? import std.range, std.traits; struct Array2(T) { private T[] _payload;

Re: Large binary size using std.regex

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 23:40:12 + Bayan Rafeh via Digitalmars-d-learn wrote: > Renders a 1.6 megabyte binary. Is that normal? yes. this binary includes statically linked runtime and phobos, plus alot of template expansions. alas, template magic is not free. signature.asc Description: PGP signa

Re: Large binary size using std.regex

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sat, 23 Aug 2014 23:40:12 + Bayan Rafeh via Digitalmars-d-learn wrote: p.s. strip it. stripping debug info can significantly reduce binary size. for your example: unstripped elf: 1,674,653 bytes stripped elf : 1,074,528 bytes signature.asc Description: PGP signature

Re: Large binary size using std.regex

2014-08-23 Thread Artem Tarasov via Digitalmars-d-learn
On Sunday, 24 August 2014 at 03:14:33 UTC, ketmar via Digitalmars-d-learn wrote: yes. this binary includes statically linked runtime and phobos, plus alot of template expansions. alas, template magic is not free. OTOH, on Linux latest LDC does far better job in eliminating dead code than DMD:

Re: Large binary size using std.regex

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sun, 24 Aug 2014 06:10:20 + Artem Tarasov via Digitalmars-d-learn wrote: > OTOH, on Linux latest LDC does far better job in eliminating dead > code than DMD: does ldc uses shared runtime here? with dmd -defaultlib=libphobos2.so test.d i got 657,438 bytes (425,836 stripped). seems tha

Re: Large binary size using std.regex

2014-08-23 Thread Artem Tarasov via Digitalmars-d-learn
On Sunday, 24 August 2014 at 06:20:38 UTC, ketmar via Digitalmars-d-learn wrote: does ldc uses shared runtime here? No, it doesn't: $ ldd test linux-vdso.so.1 (0x7fffce266000) librt.so.1 => /usr/lib/librt.so.1 (0x7fc174193000) libdl.so.2 => /usr/lib/libdl.so.2 (0

Re: Large binary size using std.regex

2014-08-23 Thread ketmar via Digitalmars-d-learn
On Sun, 24 Aug 2014 06:36:01 + Artem Tarasov via Digitalmars-d-learn wrote: > On Sunday, 24 August 2014 at 06:20:38 UTC, ketmar via > Digitalmars-d-learn wrote: > > does ldc uses shared runtime here? > No, it doesn't: hm. ldc rocks. ;-) signature.asc Description: PGP signature