Re: Problem Linking Phobos git master
On Saturday, 5 July 2014 at 02:13:39 UTC, Kapps wrote: Possibly something related to: https://github.com/D-Programming-Language/dmd/pull/3715 Have you tried updating to git master today? Yes, unfortunately with the same problem (with ld.bfd). With ld.gold I get a huge amount of errors: ../dmd/src/dmd -I/home/per/opt/x86_64-unknown-linux-gnu/dmd/include/d2 -shared -debuglib= -defaultlib= -ofgenerated/linux/release/64/libphobos2.so.0.66.0 -L-soname=libphobos2.so.0.66 ../druntime/lib/libdruntime-linux64so.a -L-ldl -Lgenerated/linux/release/64/libcurl_stub.so std/algorithm.d std/array.d std/ascii.d std/base64.d std/bigint.d std/bitmanip.d std/compiler.d std/complex.d std/concurrency.d std/conv.d std/cstream.d std/csv.d std/datetime.d std/demangle.d std/encoding.d std/exception.d std/file.d std/format.d std/functional.d std/getopt.d std/json.d std/math.d std/mathspecial.d std/mmfile.d std/numeric.d std/outbuffer.d std/parallelism.d std/path.d std/process.d std/random.d std/range.d std/regex.d std/signals.d std/socket.d std/socketstream.d std/stdint.d std/stdio.d std/stdiobase.d std/stream.d std/string.d std/syserror.d std/system.d std/traits.d std/typecons.d std/typetuple.d std/uni.d std/uri.d std/utf.d std/uuid.d std/variant.d std/xml.d std/zip.d std/zlib.d std/c/linux/linux.d std/c/linux/socket.d etc/c/curl.d etc/c/sqlite3.d etc/c/zlib.d std/c/fenv.d std/c/locale.d std/c/math.d std/c/process.d std/c/stdarg.d std/c/stddef.d std/c/stdio.d std/c/stdlib.d std/c/string.d std/c/time.d std/c/wcharh.d std/internal/digest/sha_SSSE3.d std/internal/math/biguintcore.d std/internal/math/biguintnoasm.d std/internal/math/biguintx86.d std/internal/math/gammafunction.d std/internal/math/errorfunction.d std/internal/processinit.d std/internal/unicode_tables.d std/internal/scopebuffer.d std/internal/unicode_comp.d std/internal/unicode_decomp.d std/internal/unicode_grapheme.d std/internal/unicode_norm.d std/net/isemail.d std/net/curl.d std/digest/digest.d std/digest/crc.d std/digest/md.d std/digest/ripemd.d std/digest/sha.d std/container/package.d std/container/array.d std/container/binaryheap.d std/container/dlist.d std/container/rbtree.d std/container/slist.d std/container/util.d generated/linux/release/64/etc/c/zlib/adler32.o generated/linux/release/64/etc/c/zlib/compress.o generated/linux/release/64/etc/c/zlib/crc32.o generated/linux/release/64/etc/c/zlib/deflate.o generated/linux/release/64/etc/c/zlib/gzclose.o generated/linux/release/64/etc/c/zlib/gzlib.o generated/linux/release/64/etc/c/zlib/gzread.o generated/linux/release/64/etc/c/zlib/gzwrite.o generated/linux/release/64/etc/c/zlib/infback.o generated/linux/release/64/etc/c/zlib/inffast.o generated/linux/release/64/etc/c/zlib/inflate.o generated/linux/release/64/etc/c/zlib/inftrees.o generated/linux/release/64/etc/c/zlib/trees.o generated/linux/release/64/etc/c/zlib/uncompr.o generated/linux/release/64/etc/c/zlib/zutil.o std/mmfile.d(344): Deprecation: alias core.sys.posix.sys.mman.MAP_ANON is deprecated - Please use core.sys.linux.sys.mman for non-POSIX extensions std/mmfile.d(344): Deprecation: alias core.sys.posix.sys.mman.MAP_ANON is deprecated - Please use core.sys.linux.sys.mman for non-POSIX extensions /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D6object23__T11_trustedDupTxaTyaZ11_trustedDupFNaNbNeAxaZAya' which may overflow at runtime; recompile with -fPIC /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D6object15__T4_dupTxaTyaZ4_dupFNaNbAxaZAya' which may overflow at runtime; recompile with -fPIC /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D6object14__T7_rawDupTaZ7_rawDupFNaNbANgaZANga' which may overflow at runtime; recompile with -fPIC /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D11TypeInfo_ya6__initZ' which may overflow at runtime; recompile with -fPIC /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D6object22__T11_trustedDupTxaTaZ11_trustedDupFNaNbNeAxaZAa' which may overflow at runtime; recompile with -fPIC /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D6object14__T4_dupTxaTaZ4_dupFNaNbAxaZAa' which may overflow at runtime; recompile with -fPIC /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D6object14__T7_rawDupTaZ7_rawDupFNaNbANgaZANga' which may overflow at runtime; recompile with -fPIC /usr/bin/ld: error: generated/linux/release/64/libphobos2.so.0.66.o: requires dynamic R_X86_64_PC32 reloc against '_D6object22__T11_trustedDupTxmTmZ11_trustedDupFNaNbNeAxmZAm' which may overflow at
Re: Problem Linking Phobos git master
On Saturday, 5 July 2014 at 09:54:21 UTC, Nordlöw wrote: On Saturday, 5 July 2014 at 02:13:39 UTC, Kapps wrote: Possibly something related to: https://github.com/D-Programming-Language/dmd/pull/3715 Have you tried updating to git master today? Yes, unfortunately with the same problem (with ld.bfd). There's something wrong with build script that triggers the error. I'm looking into it... /Per
Re: Problem Linking Phobos git master
On 07/05/2014 12:13 AM, Nordlöw wrote: On Ubuntu 14.04 my git master build script for phobos now fails as below. Why? Help please. /usr/bin/ld points to /usr/bin/ld.bfd on my system Terminal echo and error message follows: ../dmd/src/dmd -I/home/per/opt/x86_64-unknown-linux-gnu/dmd/include/d2 -shared -debuglib= -defaultlib= ... Do you have an DFLAGS environment variable set on your system? It looks like the environment variable is used instead of the make file variable while compiling. -- Mike Wey
Slow compilation using a lib with template methods
Hello community, here is a post with multiple questions regarding compile times, or rather the optimization of the compile and link process. I work with VisualD and am interested in optimizing my projects with this utility, hence there will be a similar topic linking here, where I explain my solution an projects setup. One of the advertised advantages of D is compiler speed. Hence I think that I do some mistakes, as my ( hobby ) projects consist of a quite small code base. The more I learn about the language, the more features I use, the more my compile times increase. I guess my usage of these features, template in particular, are not well designed. Question 1) How can I profile my compile times ? I have some guesses, but they might be wrong. Question 2) Is there a good read about the intermediate files dmd creates (e.g. *.obj, *.def), and how they might be utilized to improve compile times ( incremental compilation? ) ? Next I need to explain some details about my codebase: I use a lib, lets call it MyLib, which consists of about 15 modules, each 300 lines of code in average. Most of the modules consist of one class and some of these classes have one or two template methods. I link this lib statically to another ( one ) lib I created from some DerelictOrg modules. Projects which use MyLib consist of about five modules which have aprox 200 lines of code in average. I would say this is a small codebase. I use MyLib all of these projects, and about the time I introduced template methods in MyLib I noticed a slow down in compiling and linking ( but I cannot tell for sure that the compile time is related to the template method, however lets assume it is ). Before that my projects used to build in five seconds max, now it is more like 30 seconds, and most of the time is spend in building MyLib. My guess is that MyLib is completely rebuild when I use it in a projects with differently typed calls to the template methods. Question 3) How smart is dmd in separating template from non-template code, in particular if both codeblocks are defined in the same module / class ? How can I assist dmd in determining and/or keeping files necessary for incremental compilation and linking ? One step deeper into MyLib. All the template methods have only one type parameter. I use arbitrary typed Arrays, generate some information about the type with compile time reflection ( primitive and struct types ), and call a non-template method which takes a void[] array and the extracted type information. That made me think about GOF Decorator pattern via UFCS. Unfortunately, I guess due to the restrictions mentioned in the docs for UFCS ( , I do not get it to work. Here is my approach: /// file LibModule.d module LibModule; struct TypeDescriptor { ... } class NonTemplate { void nonTemplateMethod( void[] array , TypeDescriptor typeDescriptor ) { ... } } void templateFunction(T)( NonTemplate nonTemplate , T[] array ) { auto typeDescriptor = ... /// mindblowing compile-time magic nonTemplate.nonTemplateMethod( array , typeDescriptor ); } ... /// Usage in file MainModule.d module MainModule; import LibModule; float[100] floatArray; auto nonTemplate = new NonTemplate; nonTemplate.templateFunction( floatArray ); ... Question 4) This does not work, how can I make it work ? It also did not work with a separate module TemplateModule for templateFunction, tried to import TemplateModule in LibModule as well as in MainModule. Question 5) Would this improve my compilation speed at all ? How would I compile and link only non template modules/classes in my lib and still be able to use templateFunction in the described UFCS way ? The following question is valid if only I get answer like: Not possible due to UFCS restrictions Specification of UFCS is presented with an example explaining the restrictions, which quite confuses me: Question 6) The example given as reasoning to UFCS restrictions, isn't that using symbol shadowing, which is deprecated ? How could Walter and Andrei be asked politely to loosen these restrictions, as the gain in functionality is significant compared to the ( unlikely ? ) example scenario ? Thanks in advance for any advice. Cheers, ParticlePeter
Visual D: Settings to Improve compil and link process
Hello Community, I thought there's a separate forum for VisualD. It did exist when VisualD was on DSource, so why not add it here as well? Or am I to blind to see? Anyway, this thread is an addition to my previous one in this forum: http://forum.dlang.org/thread/wkkuvzkzeupyfdpwe...@forum.dlang.org I noticed increasing compile times in my projects. As I use only VisualD I would like to understand how I would shorten compile time with this tool. Brief description to my setup, more details can be fond in the other post. I have one Lib, called MyLib consisting of around 15 modules, one class per module, zero to two template methods per class with one type parameter each. All my projects use MyLib, and call the template methods with different types. Most of the compile time of any of theses projects is spent in rebuilding MyLib. I am not sure why and where so much time is spent, but is there a way to profile my COMPILE time with VisualD? There are several VisualD project properties which I do not understand fully, but hope that they might help, namely: Configuration Properties - General - Files to clean Configuration Properties - Compiler - Output - Multiple Object Files Configuration Properties - Compiler - Output - Keep Path From Source File Could not cleaning some files improve compilation ? Could Multiple Object Files be used to separately compile non-template and template code blocks ? What does Keep Path From Source File do at all ? It is possible to remove the template methods from my classes, create free functions instead and use them in a UFCS way. Unfortunately I have not figured out UFCS properly, as my approaches do not work ( guess due to UFCS restrictions ). Anyway, would it help ( and is it possible at all ) to put the template functions in a separate module so that only the corresponding object file requires a recompile ? I am asking in the context of the Multiple Object Files setting. I tried to not build MyLib at all, and use the sources directly, but the project setup is kind of confusing. Again, there is a setting which I seem to not understand fully. So one project, lets say MyProject, has only its own module files added to the VisualD project. I want the compiler to also use the MyLib source files, but do not want to add them to MyProject, reasoning bellow. There is one entry in the project properties, which should make this behavior possible, but it doses not. Why ? Configuration Properties - Compiler - General - Additional Imports As far as I understand this setting, I am supposed to enter module search paths. But I do get linker errors when I do not add either MyLib.lib to the linker settings or all the source files of MyLib to MyProject. Reasoning why I do not want to do this: I have one solution file with the MyLib project and ten projects like MyProject using MyLib. I would need to add all the source files to all the projects, they would be reachable and editable at 11 different location within my solution file. This does not not seem to be a clean way to set it up. Any advice to any or all the thoughts and issues ? Thanks in advance. Cheers, ParticlePeter
Re: break on assertion in GDB?
The reason it worked one time and not the other was because the other time was an exception, not an assertion. How do I break on exceptions? (ps. is there a guide anywhere to using GDB with D?)
std.algorithm.map with multiple lambdas (2.066.0-b1) (does not compile)
void main(){ import std.algorithm, std.stdio; auto arr = [1,2,3]; arr.map!(a + a, a * a).writeln; //compiles arr.map!(a = a + a, a = a * a).writeln; //does not } If I define two functions outside main, it works: void main(){ import std.algorithm, std.stdio; auto arr = [1,2,3]; arr.map!(twoTimes, square).writeln; } int square(int i){ return i*i; } int twoTimes(int i){ return i+i; } However, if `twoTimes` and `square` are nested inside of main(), it fails. [...]\typetuple.d(550): Error: template instance F!(twoTimes) cannot use local 'twoTimes' as parameter to non-global template AppliedReturnType(alias f) [...]\typetuple.d(556): Error: template instance maptest.main.staticMap!(AppliedReturnType, twoTimes) error instantiating [...]\algorithm.d(415):instantiated from here: staticMap!(AppliedReturnType, twoTimes, square) .\maptest.d(8):instantiated from here: map!(int[]) The alias declaration `alias AppliedReturnType(alias f) = typeof(f(r.front));` ... is something I have never seen before. So I hardcoded/expanded this line: `alias ReturnTypes = TypeTuple!(AppliedReturnType!(_funs[0]), AppliedReturnType!(_funs[1]));` ... which gives me the same error (cannot use local as parameter to non-global). So I threw it in a pragma(msg, [...]): `pragma(msg, TypeTuple!(AppliedReturnType!(_funs[0]), AppliedReturnType!(_funs[1])));` ... which printed `(int, int)`, as expected. And also the same error. Wat.
What exactly module in D means?
I've been reading the newsgroup for a while, and it seems that one of the reason folks like D is because it supports module. My question is: what does module mean? A quick google pointed my this page: http://dlang.org/module.html. Still cannot understand it, though :) How does it differ from the old C's #include? For example, consider the hello world in C. #include stdio.h int main(void){ printf(%s\n, Hello world...); return 0; } The C preprocessor while replace the line #include stdio.h with the content of stdio.h itself. While in D: import std.stdio; void main(){ writeln(Hello world...); } Does that mean the compiler take the definition of writeln itself from stdio.d and paste it into my program? Pardon my ignorance, because I'm not versed in compiler theory.
Trouble initializing a templated class
I'm going through Adam Wilson's talk 'C# to D' and I've gotten hung up by one of his examples regarding generic programming in D. Specifically, I'm trying to implement the code example found here: http://youtu.be/6_xdfSVRrKo?t=16m44s. I created a templateExp.d file that looks like this: public class BaseClass {} public class OtherClass : BaseClass {} class SomeClass(T : BaseClass) { public T[] values; public void add(T input) { values ~= input; } } void main() { auto sc = new SomeClass(); OtherClass oc1 = new OtherClass(); OtherClass oc2 = new OtherClass(); sc.add(oc1); sc.add(oc2); import std.stdio; writefln(value count, sc.values.length); } When I run the dmd compiler, I get this error: dmd templateExp.d teamplteExp.d(12): Error: class teamplteExp.SomeClass(T : BaseClass) is used as a type How can I initialize this class correctly?
Re: Trouble initializing a templated class
When I run the dmd compiler, I get this error: dmd templateExp.d teamplteExp.d(12): Error: class teamplteExp.SomeClass(T : BaseClass) is used as a type This is actually: templateExp.d(12): Error: class templateExp.SomeClass(T : BaseClass) is used as a type
Re: Trouble initializing a templated class
On Saturday, 5 July 2014 at 16:47:32 UTC, quakkels wrote: I'm going through Adam Wilson's talk 'C# to D' and I've gotten hung up by one of his examples regarding generic programming in D. Specifically, I'm trying to implement the code example found here: http://youtu.be/6_xdfSVRrKo?t=16m44s. I created a templateExp.d file that looks like this: public class BaseClass {} public class OtherClass : BaseClass {} class SomeClass(T : BaseClass) { public T[] values; public void add(T input) { values ~= input; } } void main() { auto sc = new SomeClass(); OtherClass oc1 = new OtherClass(); OtherClass oc2 = new OtherClass(); sc.add(oc1); sc.add(oc2); import std.stdio; writefln(value count, sc.values.length); } When I run the dmd compiler, I get this error: dmd templateExp.d teamplteExp.d(12): Error: class teamplteExp.SomeClass(T : BaseClass) is used as a type How can I initialize this class correctly? try SomeClass (T): BaseClass
Re: What exactly module in D means?
No, import is different from include. It does not stupidly copy and paste its content but tells the compiler to take the module into account for name resolution. The result may seem similar, but is much more efficient. A D module is also a unit of encapsulation (a private declaration in a module is only accessible from this module, and not from another one importing it).
Re: Trouble initializing a templated class
On Saturday, 5 July 2014 at 17:17:03 UTC, quakkels wrote: try SomeClass (T): BaseClass Not sure which line you want me to change. I don't want SomeClass to inherit from BaseClass. Rather, I want T to be restricted to classes that inherit from BaseClass. When I change `class SomeClass(T : BaseClass)` to `class SomeClass(T) : BaseClass` I still get the class templateExp.SomeClass(T) is used as a type error. ah, sorry, I misunderstood. It looks like you need to change the lin auto sc = new SomeClass (); to auto sc = new SomeClass!BaseClass (); The compiler complains because SomeClass is a template when you call SomeClass() without !() template parameters. It only becomes a type once instantiated with parameters.
Re: Trouble initializing a templated class
try SomeClass (T): BaseClass Not sure which line you want me to change. I don't want SomeClass to inherit from BaseClass. Rather, I want T to be restricted to classes that inherit from BaseClass. When I change `class SomeClass(T : BaseClass)` to `class SomeClass(T) : BaseClass` I still get the class templateExp.SomeClass(T) is used as a type error.
Re: std.algorithm.map with multiple lambdas (2.066.0-b1) (does not compile)
This is an instance of these bugs: https://issues.dlang.org/show_bug.cgi?id=5710 https://issues.dlang.org/show_bug.cgi?id=11946 But seeing that `map` works with a single lambda/local function, it should be possible to make it work with several ones too. For the time being, a simple workaround is to make the local functions static: void main() { static int square(int i) { return i*i; } static int twoTimes(int i) { return i+i; } import std.algorithm, std.stdio; auto arr = [1,2,3]; arr.map!(twoTimes, square).writeln; }
Re: What exactly module in D means?
On Saturday, 5 July 2014 at 17:08:01 UTC, Olivier Pisano wrote: No, import is different from include. It does not stupidly copy and paste its content but tells the compiler to take the module into account for name resolution. The result may seem similar, but is much more efficient. In fact, try to write the following C code: int main() { #include stdio.h [whatever else you want] } and look at those lovely error messages from the compiler :P
Re: Trouble initializing a templated class
ah, sorry, I misunderstood. It looks like you need to change the lin auto sc = new SomeClass (); to auto sc = new SomeClass!BaseClass (); The compiler complains because SomeClass is a template when you call SomeClass() without !() template parameters. It only becomes a type once instantiated with parameters. Thanks. That did it. Here's my working program. public class BaseClass {} public class OtherClass : BaseClass {} class SomeClass(T : BaseClass) { public T[] values; public void add(T input) { values ~= input; } } void main() { auto sc = new SomeClass!BaseClass(); OtherClass oc1 = new OtherClass(); OtherClass oc2 = new OtherClass(); sc.add(oc1); sc.add(oc2); import std.stdio; writefln(value count: %d, sc.values.length); }
File needs to be closed on Windows but not on Posix, bug?
I ran into this when trying to fix the Phobos unit tests and have reduced it down to this test file: import std.stdio, std.file; void main() { auto f = File(test.txt, w); //f.close(); std.file.remove(test.txt); } This compiles and runs fine on linux and the autotester shows that it works on all the tested Posix platforms, but it fails on Windows with std.file.FileException@std\file.d(433): test.txt: The process cannot access the file because it is being used by another process. Uncommenting the f.close() gets it to work fine on all supported platforms, no doubt it has to do with the different OS APIs that are being called. This seems like inconsistent behavior: should I file a bug?
Re: What exactly module in D means?
On Saturday, 5 July 2014 at 16:35:31 UTC, Andre Tampubolon wrote: I've been reading the newsgroup for a while, and it seems that one of the reason folks like D is because it supports module. My question is: what does module mean? A quick google pointed my this page: http://dlang.org/module.html. Still cannot understand it, though :) How does it differ from the old C's #include? For example, consider the hello world in C. #include stdio.h int main(void){ printf(%s\n, Hello world...); return 0; } The C preprocessor while replace the line #include stdio.h with the content of stdio.h itself. While in D: import std.stdio; void main(){ writeln(Hello world...); } Does that mean the compiler take the definition of writeln itself from stdio.d and paste it into my program? Pardon my ignorance, because I'm not versed in compiler theory. You might find the clang docs on C++ modules worthwhile, though they do it somewhat differently from D: http://clang.llvm.org/docs/Modules.html An #include simply copies and pastes the entire contents of the C/C++ header into your source, which can happen over and over again in a large project with no include guards, while modules are a more sophisticated way of separating code.
Re: File needs to be closed on Windows but not on Posix, bug?
On Saturday, 5 July 2014 at 20:23:03 UTC, Joakim wrote: This seems like inconsistent behavior: should I file a bug? This is because the operating systems do it differently; I think D is doing the right thing by being a pretty thin wrapper around that functionality. If anything, I'd just say deleting an open file may not be permitted in the docs, implying that the user should always close it themselves before deleting it.
Re: std.algorithm.map with multiple lambdas (2.066.0-b1) (does not compile)
On Saturday, 5 July 2014 at 19:31:24 UTC, Marc Schütz wrote: This is an instance of these bugs: https://issues.dlang.org/show_bug.cgi?id=5710 https://issues.dlang.org/show_bug.cgi?id=11946 But seeing that `map` works with a single lambda/local function, it should be possible to make it work with several ones too. For the time being, a simple workaround is to make the local functions static: This problem was introduced when std.algorithm.map was made to refuse void functions. But map already did fail void when it gets multiple functions, because std.typecons.tuple refuses variables of type void (though the error message is cryptic, sure): Error: variable std.typecons.Tuple!void.Tuple._expand_field_0 variables cannot be of type void The only thing map didn't fail was single argument void. This was fixed, so why not re-use the same fix for multiple arguments? The example below works fine, and gives the new and sensible-er error message: template map(fun...) if (fun.length = 1) { auto map(Range)(Range r) if (isInputRange!(Unqual!Range)) { alias AppliedReturnType(alias f) = typeof(f(r.front)); static if (fun.length 1) { import std.functional : adjoin; import std.typetuple : staticIndexOf; alias _funs = staticMap!(unaryFun, fun); alias _fun = adjoin!_funs; // Attack of the copy-paste and poorly chosen variable name: foreach(_f; _funs){ static assert(!is(AppliedReturnType!_f == void), All mapping functions must not return void.); } } else { alias _fun = unaryFun!fun; static assert(!is(AppliedReturnType!_fun == void), Mapping function must not return void.); } return MapResult!(_fun, Range)(r); } } Am I missing something?
Re: implib and system dlls, oh my
On Tuesday, 24 June 2014 at 12:56:28 UTC, Jason King wrote: I don't know enough about implib to explain it. But another method that I believe should work is to use linker definition files. It'll allow optlink to work. Just add it to dmd, actually I believe it needs to be passed to Optlink (so -L it). Another fix, might be to use 64bit, but shouldn't be required. [0] http://www.dsource.org/projects/bindings/wiki/DefFiles/OleAut32 Rikki, Thank you for your kind attention. I spewed to the newsgroup and googled for an answer in the wrong order. It appears the solution to this problem is the combination of coffimplib + windows SDK. After using those on the SDK's oleaut32.lib I got a library with the properly decorated _VarCmp@16. Not your job, but this could probably be made simpler. You may want to spearhead the effort to get Win32 support of MSVC into D, if you care enough about it. Rainer has done most of the work, you'd just have to turn his patches into pull requests, shepherd them through the review process, and maybe add some polish: http://forum.dlang.org/thread/mailman.1560.1323886804.24802.digitalmar...@puremagic.com?page=9#post-llldfc:242q6p:241:40digitalmars.com
Compile time definitions
Is there a way to define a compile time constant/enum with dmd? For example, inserting the svn revision number into my code? In C... #include stdio.h #ifndef SOMETHING #define SOMETHING bar #endif int main() { printf(hello world: SOMETHING \n); return 0; } gcc main.c ./a.out hello world: bar gcc -DSOMETHING=\foo\ main.c ./a.out hello world: foo How would you recommend I do something like this with D?
Re: Compile time definitions
Brenton: How would you recommend I do something like this with D? In D compile-time constants are introduced using the enum keyword. You can also use the -version=... compiler switch to compile your D code according to some version, that can be a number or identifier. In D there isn't the -D switch of gcc, so you can do something similar putting your string into a little textual file, and importing it inside the module using mixin(import(myfilename.txt)) statement plus the -Imypathname compiler switch. Bye, bearophile
Re: Using a delegate when interfacing with C
On Saturday, 5 July 2014 at 22:18:56 UTC, Marco Cosentino wrote: auto client = *(cast(ClientImplementation*) data); Try just auto client = cast(ClientImplementation) data; and this.setProcessCallback(callback, cast(void *) this); setProcessCallback(callback, cast(void*) this); Can somebody help me in figuring out why this happens? The reason is a class this in D is already a pointer (just a hidden one) so when you do this in a class, it is like a ClientImplementation** in C - a pointer to a (temporary) pointer. So by the time the callback runs, it is pointing to nonsense. In general, remember any class reference in D is already equivalent to a pointer in C or C++ and can be casted straight to void* without needing to take its address.
Re: Using a delegate when interfacing with C
On Saturday, 5 July 2014 at 22:28:48 UTC, Adam D. Ruppe wrote: In general, remember any class reference in D is already equivalent to a pointer in C or C++ and can be casted straight to void* without needing to take its address. Thanks Adam, you're a life saver ;). It works like a charme.
Re: Compile time definitions
On Saturday, 5 July 2014 at 22:08:52 UTC, bearophile wrote: Brenton: How would you recommend I do something like this with D? In D compile-time constants are introduced using the enum keyword. You can also use the -version=... compiler switch to compile your D code according to some version, that can be a number or identifier. In D there isn't the -D switch of gcc, so you can do something similar putting your string into a little textual file, and importing it inside the module using mixin(import(myfilename.txt)) statement plus the -Imypathname compiler switch. Bye, bearophile Thanks bearophile, using mixin(import(myfilename.txt)) works great.
Re: How to test templates for equality?
I have another question about testing if given symbol is instance of the given template and geting it's template arguments. I'm talking about raw template symbols, but not struct or class templates. For case with struct or class template std.traits.isInstanceOf is working well. But using *raw* template is not possible for it. There is an example. import std.stdio, std.traits; template WrapperTemplate(T) {} void main() { writeln( isInstanceOf!(WrapperTemplate, WrapperTemplate!(int)) ); } Because isInstanceOf implemented as *is* expression it expects type arguments, but template is not type at all. So this is not working. As we have __traits(isSame, ...) we could make such a test, but I need to have tuple of template arguments. But I don't understand how to get them template isMyInstanceOf(alias Templ, alias Inst) { }
Re: How to test templates for equality?
Suddenly posted. I don't know why it's happened)) template isMyInstanceOf(alias Templ, alias Inst) { alias Args = ???; //I don't have idea how to get it enum bool isMyInstanceOf = __traits(isSame, Templ!(Args), Inst); } Do you have any idea how to solve this? May be standad library could be improved with such type of test for template instance?