Re: port C++ to D - copy constness
Am 02.06.2014 12:09, schrieb Timon Gehr: On 06/02/2014 09:06 AM, dennis luehring wrote: i want to port this C++ code to good/clean D and have no real idea how to start contains 2 templates - a slice like and a binary reader for an slice main idea was to copy the immutablity of the slice data to the reader http://pastebin.com/XX2yhm8D the example compiles fine with http://gcc.godbolt.org/, clang version 3.4.1 and compiler-options: -O2 -std=c++11 the slice_T template - could be maybe reduce down to an normal D slice but i want to control the slice (im)mutability - so maybe there is still a need for the slice_T thing i don't know if the binary reader read_ref method should be written totaly different in D any tips, ideas? If the following is not already what you were looking for, it should get you started. (But note that the interface provided by BinaryReader is unsafe: It may invent pointers. You might want to add template constraints that would at least allow the implementation to be @trusted.) template CopyQualifiers(S,T){ import std.traits; static if(is(S==const)) alias T1=const(Unqual!T); else alias T1=Unqual!T; static if(is(S==immutable)) alias T2=immutable(T1); else alias T2=T1; static if(is(S==inout)) alias T3=inout(T2); else alias T3=T2; static if(is(S==shared)) alias CopyQualifiers=shared(T3); else alias CopyQualifiers=T3; } struct BinaryReader(T){ @disable this(); this(T[] slice){ this.slice=slice; } size_t left()const{ return slice.length - offset; } bool enoughSpaceLeft(size_t size)const{ return size <= left(); } ref readRef(V)(){ if(!enoughSpaceLeft(V.sizeof)) throw new Exception("1"); auto off=offset; offset+=V.sizeof; return *cast(CopyQualifiers!(T,V)*)(slice.ptr+off); } auto readValue(V)(){ return readRef!V(); } private: T[] slice; size_t offset=0; } auto binaryReader(T)(T[] slice){ return BinaryReader!T(slice); } void main(){ import std.stdio; try{ auto testData = "THIS IS BINARY TEST DATA"; // no comment auto stream = binaryReader(testData); static assert(is(typeof(stream.readRef!uint())==immutable)); (ref ref_){ auto value = stream.readValue!uint(); }(stream.readRef!uint()); }catch(Exception e){ writeln("exception error: ",e.msg); }catch{ writeln("exception unknown"); } } seems to be a good start - how would you implement such slice/reader thing in idiomatic D style - the same?
port C++ to D - copy constness
i want to port this C++ code to good/clean D and have no real idea how to start contains 2 templates - a slice like and a binary reader for an slice main idea was to copy the immutablity of the slice data to the reader http://pastebin.com/XX2yhm8D the example compiles fine with http://gcc.godbolt.org/, clang version 3.4.1 and compiler-options: -O2 -std=c++11 the slice_T template - could be maybe reduce down to an normal D slice but i want to control the slice (im)mutability - so maybe there is still a need for the slice_T thing i don't know if the binary reader read_ref method should be written totaly different in D any tips, ideas?
Re: Cost of assoc array?
Am 14.05.2014 15:20, schrieb Chris: Profiling is not really feasible, because for this to work properly, I would have to introduce the change first to be able to compare both. Nothing worse than carefully changing things only to find out, it doesn't really speed up things. why not using an alias for easier switch between the versions? alias string[][size_t] my_array_type or alias string[][] my_array_type an do an search&replace of "string[][size_t]" with "my_array_type" thats it - still too hard :)
Re: Cost of assoc array?
Am 14.05.2014 12:33, schrieb Chris: On Wednesday, 14 May 2014 at 10:20:51 UTC, bearophile wrote: Chris: Is there any huge difference as regards performance and memory footprint between the two? Or is 2. basically 1. under the hood? An associative array is a rather more complex data structure, so if you don't need it, use something simpler. There is difference in both the amount of memory used and performance (in many cases such difference doesn't matter). In D there are also differences in the way they are initialized from a null or fat null. Bye, bearophile Thanks. Do you mean the difference is negligible in many cases? I'm not sure, because changing it would be a breaking change in the old code, meaning I would have to change various methods. a simple array would be faster because no access is generate for your key - just plain access, just don't use assoc arrays if you don't need key based access read more manuals about hashmaps and stuff and how to do benchmarking - helps alot in the future
Re: Interface to Microsoft Access database (Jet)
Am 11.03.2014 09:06, schrieb Orfeo: Thank you for github link, I had tried only with mdbtools on http://mdbtools.sourceforge.net/... So, it seems that I can connect using libmdb or odbc ... so everything is fine? or "I can not" have you any suggestions? answer the question what do you need?
Re: Interface to Microsoft Access database (Jet)
Am 11.03.2014 08:37, schrieb Orfeo: I should extract and process data from Microsoft Access database, and mdbtools is not enough. Is there a library that I can use to query Access? Thanks "mdbtools is not enough" what is not enough? what "version" of mdbtools do you use https://github.com/brianb/mdbtools
Re: TLF = thread local functions
Am 23.01.2014 15:44, schrieb Frustrated: So, TLS solves the data issue with threading. I just thought, with out much thinking, what about having thread local functions? Doesn't make sense? Let me explain. Functions generally are not thread safe because of reentry, right? The same data is used by the function for each thread calling it and sense threads could effectively call a function while the same function is being executed by another thread, the data is correct. no - the parameters and local vars of the function are in the stack of the thread - so there is no problem with them, only shared variables can have a need to synchronization your idea tries to solve non existing problems?
Re: Disassembly Tool
Am 14.11.2013 10:48, schrieb Namespace: Since the disassembly on Dpaste doesn't work for me anymore, I'm looking for an alternative. Is there one? And I don't want obj2asm, I'm not willing to pay 15$. maybe: distorm: http://www.ragestorm.net/distorm/ ida freeware: https://www.hex-rays.com/products/ida/support/download_freeware.shtml (32bit only) agner fogs: http://www.agner.org/optimize/#objconv
Re: Which option is faster...
Am 07.08.2013 06:30, schrieb jicman: Again, what are you trying to achieve? Your statement is not necessarily true, for a myriad of reasons, but it entirely depends on what you want to do. I would reiterate Dennis Luehring's reply, why are you not benching? It seems like you are guessing at what the problems are, that's hardly ever useful. One of the first rules of network optimization is to reduce the amount od data, that normally means filtering.at the server, the next thing is coarse grained is better than fine (BOCTAOE/L). It's a long story and I will return in a few months and give you the whole story, but right now, time is not on my side. I have answers for all the questions you folks have asked, and I appreciate all the input. I have the answer that I was looking for, so in a few months, I will come back and explain the whole story. Thanks for all the response and suggestions. after makeing us girls all wet to help you - your reply is "no sex on the first date, im a gentlemen... but maybe in a few months" so: you having a jscript doing somehting with files,fileextensions over networkdrive - it runs around 8h you ported that jscript to D - now it runs for 6h you noob-guessed the lowercase-if-party could be evil (btw: it cost more time to guess then to benchmark) you get trivial answers that won't get you very much, the lowercase would not boost your speed that much and the networkdrive latency will kill all the other statemachine ideas you don't answer trivial questions about the big picture - and now you're out of time open questions: -why not collect the data on the server itself - instead of grabbing tiny bits over network? - this is for understanding your environent -how big is the speed drop with your tool on the very same drive localy and over a networkdrive? - this is for understanding the latency -are you also reading this files or just doing filename search (recursively?) and throwing out non office-extensions? this is for getting an idea if buildin OS(operating system) features can help see you in a few months
Re: Getting number of messages in MessageBox
Am 06.08.2013 09:30, schrieb Marek Janukowicz: Gabi wrote: Why not go for the trivial solution - just increase/decrease a counter for each push/pop message? Yeah, that's most likely what I'll end up with, but it's a pity such information exists and I only can't access it because someone decided to make it private... or should I file a bug (or rather feature request) about it? the question is do the published counter then needs locking - and make it slow for all - just for beeing getable?
Re: Which option is faster...
Am 05.08.2013 19:04, schrieb jicman: so its totaly unclear if the presented code is your 2h monster, what was the runtime of your jscript? The files are in a network drive, so, that has some slowness already involved because of that. The jscript use to take over 8 hours. The new D program has dropped that to under less than six. This is huge to us. But, I know that I can probably fine tune the program to make it a few minutes less. :-) can you describe more detailed what are you doing - are you also reading these files? why not run your tool on the server and only collect the results over network (wouldn't that be much faster)? what is the impact of using the networkdrive? just copy your biggeste szenario on a local machine an run it against this to get a feeling how painfull the networkdrive communication is > But I see that a great idea has been provided using a local variable for not lowercasing on each if is not an great idea it is default programming style This will help. If there are 100K files, which I know that there are more than that, it will help a little bit. and i don't think you're be able to implement the tree statemachine when doing such simple performance killer like multiple lowercase calls, and try to help youselfe by introducing "continue"... Perhaps, but it's a good idea, nonetheless. maybe your program can be better optimized globaly, but we need more information of what is the programing doing - can you give some psuedo code like: 1. read all filenames recursivley -> 100k filenames 2. reduce down to known extensions -> 10k filenames 3. ... 4. ... 5. ... i don't think that your lower-case is the major part of the 6h, there must be other very slow parts in your project - which you don't find without putting in some bechmarking (and i don't understand why you don't start with benchmarking)
Re: Which option is faster...
Am 05.08.2013 17:18, schrieb jicman: > It is a tool that was a script, but I have turned it into do, which now has taken two hours from the last jscript script. I have not benchmarked it, yet. I may. But I see that a great idea has been provided, which I will use. Thanks for the help. > have not benchmarked it, yet. I may. so its totaly unclear if the presented code is your 2h monster, what was the runtime of your jscript? > But I see that a great idea has been provided using a local variable for not lowercasing on each if is not an great idea it is default programming style and i don't think you're be able to implement the tree statemachine when doing such simple performance killer like multiple lowercase calls, and try to help youselfe by introducing "continue"...
Re: Which option is faster...
> Ok, how would you make it faster? i don't see a better solution here - how to reduce ONE lowercase and SOME compares in any way? (i dont think a hash or something will help) but i know that anything like your continue-party is worth nothing (feels a little bit like script-kiddies "do it with assembler that would it make million times faster" blabla) question: is this the slow part in your project? do you know it for sure or just an emotion - HOW do you benchmark? Am 05.08.2013 16:31, schrieb jicman: On Monday, 5 August 2013 at 14:27:43 UTC, dennis luehring wrote: did you benchmarked your current szenario - how do you know that this is the slow part - or are you working on an only-extension-compare-tool? btw: they are both equal and slow - and full of partly code-duplication std.string.tolower(fext[0]) multiple times, i hope your list isn't going much longer Ok, how would you make it faster?
Re: Which option is faster...
did you benchmarked your current szenario - how do you know that this is the slow part - or are you working on an only-extension-compare-tool? btw: they are both equal and slow - and full of partly code-duplication std.string.tolower(fext[0]) multiple times, i hope your list isn't going much longer Am 05.08.2013 15:59, schrieb jicman: Greetings! I have this code, foreach (...) { if (std.string.tolower(fext[0]) == "doc" || std.string.tolower(fext[0]) == "docx" || std.string.tolower(fext[0]) == "xls" || std.string.tolower(fext[0]) == "xlsx" || std.string.tolower(fext[0]) == "ppt" || std.string.tolower(fext[0]) == "pptx") continue; } foreach (...) { if (std.string.tolower(fext[0]) == "doc") continue; if (std.string.tolower(fext[0]) == "docx") continue; if (std.string.tolower(fext[0]) == "xls") continue; if (std.string.tolower(fext[0]) == "xlsx") continue; if (std.string.tolower(fext[0]) == "ppt") continue; if (std.string.tolower(fext[0]) == "pptx") continue; ... ... } thanks. josé
Re: Socket.select interrupted system call because of GC
Am 03.08.2013 13:35, schrieb Marek Janukowicz: dennis luehring wrote: Am 03.08.2013 08:38, schrieb Marek Janukowicz: void main () { writefln( "sa: %d", SA_RESTART ); (new Thread (&serverfunc)).start(); (new Thread (&clientfunc)).start(); } i have no idea to your main problem but firing threads without any join on the threads in your main program seems very wrong to me - its like allocating memory and let system kill process handle the zombies This is of course *not* my entire program (and in fact I made the whole snippet up just to showcase the problem). While I understand your concern it doesn't really make sense to use this piece of code for anything but reproducing the issue at hand. but you should not reduce your sample down to maybe-incorrect (what it seems for me in this case) - the join wouldn't make your sample to big
Re: Socket.select interrupted system call because of GC
Am 03.08.2013 08:38, schrieb Marek Janukowicz: void main () { writefln( "sa: %d", SA_RESTART ); (new Thread (&serverfunc)).start(); (new Thread (&clientfunc)).start(); } i have no idea to your main problem but firing threads without any join on the threads in your main program seems very wrong to me - its like allocating memory and let system kill process handle the zombies
Re: Auto keyword with const variable
Am 24.07.2013 11:39, schrieb bearophile: Alex H: void test(const int n) { auto j = n; j++; } Gives this error: cannot modify const expression j Is this considered a feature or a bug? I would assume most people wouldn't want new variables inheriting const. It's a bit annoying. I don't remember people discussing this small problem. I don't know if it's easy to "fix" it and what side effects such change could cause. should that be fixed - i don't think that any auto removal of const, immutable, shared or anything else should just happen silently and how would it look to preserve the const if auto would auto-rip it of?
Re: Source code output
Am 17.07.2013 09:33, schrieb Jacob Carlborg: On 2013-07-17 05:27, JS wrote: With heavy ctfe code generation usage is it possible to have the d compiler output the source code after all mixin templates have been "used"? This way it is easier to visually check for errors in the generated code. I imagine one could use pragma in a "special way" to do this but I was hoping for something more direct. The Eclipse plugin Descent had a nice compile time view. In general it showed how the compiler lowers some features to other lower level features. I.e. "scope" is lowered to try-catch-finally. It also showed the result of string and template mixins. It was really nice to have. Too bad the plugin was abandoned. It never got any real support for D2. some videos of Descent: http://www.youtube.com/user/asterite
Re: Should it be a compile time error?
that isn't the problem - D allows assignment to an read property - and there is no write property around, so it should be an compiletime error i should compile only if the missing write property is available - or? @property int var(int value) { return _var = value; } sorry i've totaly lost seeing the write property :(
Re: Should it be a compile time error?
Am 19.06.2013 13:40, schrieb Iain Buclaw: On Wednesday, 19 June 2013 at 11:33:43 UTC, deed wrote: The following compiles and crashes with DMD 2.063. Should this be a compile time error? class A { int _var; /* SNIP */ int var() @property { return var; } Isn't the problem in this property function? (Shouldn't it return _var :o) that isn't the problem - D allows assignment to an read property - and there is no write property around, so it should be an compiletime error i should compile only if the missing write property is available - or? @property int var(int value) { return _var = value; }
Re: Latest GDB version problems
the post ist more than 3 years old Am 02.06.2013 07:04, schrieb sha0coder: (gdb) p s $1 = 578159222890430469 No luck :( try this: (gdb) x/dwx &mystirng 0xb4f4: 0x003c<- size of string (gdb) 0xb4f8: 0xb7ca2540<- ptr to the string (gdb) x/s 0xb7ca2540 0xb7ca2540: "this is my string" (gdb) add this macro to your ~/.gdbinit define ps x/s *(unsigned long *)(((char *)&$arg0)+4) end then you can do: (gdb) ps myString 0xb7ca2540: "this is my string"
Re: Why is this code returning the wrong type?
Am 23.05.2013 21:45, schrieb Gary Willoughby: Hmmm... Following your example i'm still having problems compiling this simple snippet: import std.stdio; class Example { private FILE _file; public this(string file) { this._file = File(file, "r"); } } Error: test.d(9): Error: cannot implicitly convert expression ((File __ctmp1220 = 0; , __ctmp1220).this(file, "r")) of type File to shared(_iobuf) you former private FILE* _file wasn't an File and your current private FILE _file is still not File because FILE and File is something differnt (case sensitive) why not write private File _file
Re: Linker errors and how to catch them
Am 18.02.2013 18:37, schrieb Lubos Pintes: Hi, I already did this. I am playing with that library. I converted it so that it uses win32 windows api bindings and fixed a bunch of compile errors. I also converted enum names "So_THEY_ARE_NOT_SO_UGLY". :-). Everything worked fine with 2.060. you compiled(bild) the dgui lib yourself with 2.062? i will not work if you use the prebuild ones
Re: static class
Am 17.02.2013 23:25, schrieb Jonathan M Davis: On Sunday, February 17, 2013 23:00:19 Michael wrote: > That's not the meaning of static in that context. As I understand a static class can't be instantiated. I have no idea how you came to that conclusion. That's not what it means for a class to be static at all. The only place that static has any effect on classes is for nested classes. A static, nested class is like any other class except that it's inside another class, which affects its path. e.g. i think hes refering to c# static class
is there a way to define a pure base class that forces pureness of derived classes?
i've got something like an streaming/converter system and parts of the specialised converters are stateless other statefull is there any way to force pureness/stateless-ness through the base class or an interface in D?
Re: try to compile githubs dmd-master zip with vstudio 2010
Am 27.01.2013 15:08, schrieb Namespace: You mean the Visual Studio solution? I tried it also, but for me only the solution above works fine. I asked for that problem here: http://forum.dlang.org/thread/rzvaprvvgdtwrnoto...@forum.dlang.org?page=2#post-ehulzblzddasvyxncvdb:40forum.dlang.org can you add your win32 vc build findings also to the buld wiki? http://wiki.dlang.org/Building_DMD are the missing files generated by the make process?
Re: try to compile githubs dmd-master zip with vstudio 2010
and if i want to use the solution file? Am 27.01.2013 14:45, schrieb Namespace: I had the same problem, few days ago. I wrote this short make script [1] which works for me. My solution is that you must clean before, call the vs buildme and then build again with the normal make file. Sounds weird but it works (for me). [1] makefile: set DM_HOME=D:\D cd dmd cd src make -fwin32.mak clean cd vcbuild call builddmd.bat cd .. make -fwin32.mak release copy *.exe %DM_HOME%\dmd2\windows\bin make -fwin32.mak clean pause cd ../.. cd druntime make -fwin32.mak pause cd .. cd phobos make -fwin32.mak copy phobos.lib %DM_HOME%\dmd2\windows\lib cd .. dmd
try to compile githubs dmd-master zip with vstudio 2010
i've grabbed the dmd-master.zip from github an opended the dmd_msc_vs10.sln but i get 3 errors C:\Test\dmd-master\src\mars.c wants missing include verstr.h C:\Test\dmd-master\src\c1xx missing ph.h C:\Test\dmd-master\src\c1xx missing util.c what else is needed to build from source this way?
Re: Trouble with DLL address
Just ignore my post - too early in the morning :( Am 14.01.2013 10:19, schrieb dennis luehring: http://dlang.org/type.html int => signed 32 bits but don't you need long in D Am 14.01.2013 10:13, schrieb dnewbie: I have a DLL which exports a function GetFunction. GetFunction returns a pointer to RealFunction. Now I want to run RealFunction from my D program, but for some reason I get the wrong address. Here is the code. dll64.c - #define WIN32_LEAN_AND_MEAN #include int __stdcall RealFunction(int a) { return a + 1; } typedef int (__stdcall *FuncPtr)(int); FuncPtr __stdcall GetFunction() { return &RealFunction; } mydll64.def LIBRARY mydll64.dll EXPORTS GetFunction - build with MSVC64: cl -c dll64.c -Fomydll64.obj link /DLL /OUT:mydll64.dll mydll64.obj /DEF:mydll64.def And this is the D program. testdll64d.d // dmd -m64 -c testdll64d.d -oftestdll64d.obj // link /OUT:testdll64d.exe testdll64d.obj import core.runtime; import std.c.windows.windows; import std.stdio; alias extern(Windows) int function(int) FuncPtr; int main(string[] args) { HMODULE dll = LoadLibraryA("mydll64.DLL"); FARPROC getFunction = GetProcAddress(dll, "GetFunction"); FuncPtr realFunction = cast(FuncPtr) getFunction(); writefln("dll address: %08x", dll); writefln("GetFunction address: %08x", getFunction); writefln("RealFunction address: %08x", realFunction); writefln("RealFunction result: %d", realFunction(7));//<-- CRASH return 0; } -- Output: dll address: 18000 GetFunction address: 180001020 RealFunction address: 80001000 BTW, this works: FuncPtr realFunction = cast(FuncPtr) (getFunction() & 0x | cast(size_t) dll);
Re: Trouble with DLL address
http://dlang.org/type.html int => signed 32 bits but don't you need long in D Am 14.01.2013 10:13, schrieb dnewbie: I have a DLL which exports a function GetFunction. GetFunction returns a pointer to RealFunction. Now I want to run RealFunction from my D program, but for some reason I get the wrong address. Here is the code. dll64.c - #define WIN32_LEAN_AND_MEAN #include int __stdcall RealFunction(int a) { return a + 1; } typedef int (__stdcall *FuncPtr)(int); FuncPtr __stdcall GetFunction() { return &RealFunction; } mydll64.def LIBRARY mydll64.dll EXPORTS GetFunction - build with MSVC64: cl -c dll64.c -Fomydll64.obj link /DLL /OUT:mydll64.dll mydll64.obj /DEF:mydll64.def And this is the D program. testdll64d.d // dmd -m64 -c testdll64d.d -oftestdll64d.obj // link /OUT:testdll64d.exe testdll64d.obj import core.runtime; import std.c.windows.windows; import std.stdio; alias extern(Windows) int function(int) FuncPtr; int main(string[] args) { HMODULE dll = LoadLibraryA("mydll64.DLL"); FARPROC getFunction = GetProcAddress(dll, "GetFunction"); FuncPtr realFunction = cast(FuncPtr) getFunction(); writefln("dll address: %08x", dll); writefln("GetFunction address: %08x", getFunction); writefln("RealFunction address: %08x", realFunction); writefln("RealFunction result: %d", realFunction(7));//<-- CRASH return 0; } -- Output: dll address: 18000 GetFunction address: 180001020 RealFunction address: 80001000 BTW, this works: FuncPtr realFunction = cast(FuncPtr) (getFunction() & 0x | cast(size_t) dll);
Re: Inner function overload bug?
Am 09.01.2013 14:21, schrieb Philippe Sigaud: On Wed, Jan 9, 2013 at 12:52 PM, Era Scarecrow wrote: That's weird. Why does that work? Directly pasting the mixin content in main() does not compile, right? I can only assume if it does work, that the mixin template has it's own scope that enables the overloading. If you can't do it with one, you shouldn't be allowed to do it with the other. That must be it. mixin can have names (mixin TemplateName AliasName;) which the functions as a disambiguator. I don't have access to a D compiler right now. Does this work?: void main() { { void test(ref int x) { x = test(); } int test() { return 1; } } int x; test(x); assert(x == 1); } Overloading within nested functions is likely a rare use case. I hit it while trying to change a module from struct+methods to purely functions everywhere, to see if there were any efficiency difference. http://dpaste.dzfl.pl/ ist your friend Compilation output: /home/c250/c278.d(4): Error: function c278.main.test (ref int x) is not callable using argument types () /home/c250/c278.d(4): Error: expected 1 function arguments, not 0 /home/c250/c278.d(5): Error: declaration test is already defined /home/c250/c278.d(8): Error: undefined identifier test
Re: Inner function overload bug?
Am 08.01.2013 22:43, schrieb Era Scarecrow: On Tuesday, 8 January 2013 at 21:12:34 UTC, Philippe Sigaud wrote: It's conform to the spec http://dlang.org/function.html Last line of the 'nested functions' subsection: "Nested functions cannot be overloaded." Nested functions cannot be overloaded. Hmm I seemed to have missed that. That just means my unittest wouldn't work, so either it has to be global or inside a struct/union/class (and global is not very likely). Thanks for clearing that up. isn't that some sort of hijacking then?
Re: static code generation
Am 13.12.2012 04:32, schrieb js.mdnq: I think the issue I have with all this is that when you put code inside a string you lose a lot of compile time features AFAICT. your right - but...try to come up with an similar ("easy" to implement) powerfull solution that is not based on strings and you will see how hard it is to get it right - thats the reason for string based mixins
Re: float[] → Vertex[] – decreases performance by 1000%
Am 26.07.2012 21:18, schrieb David: Hm. Do you ever do pointer arithmetic on Vertex*? Is the size and offsets are correct (like in Vertex vs float)? No, yes. I really have no idea why this happens, I saved the contents of my buffers and compared them with the buffers of the `float[]` version (thanks to `git checkout`) and they were exactly 100% the same. It's a mystery. can you create a version of you code thats allows switching (version(Vertex) else ...) between array and Vertex? or provide both versions here again you checked dmd and ldc output so it can't be a backend thing (maybe frontend or GC) - or mysterious GL bugs
Re: Immutability and other attributes, please review
Am 15.06.2012 08:25, schrieb Jacob Carlborg: On 2012-06-14 17:32, Roman D. Boiko wrote: I agree, just looking how to accomplish my goals. I decided to get rid of casting, and will store everything on heap. I don't know how to put a variable of type float to the heap, and thought that it would be nice to allow the user to pass anything inside, but copy when that is not an l-value. Do you really need to put a float on the heap? Just pass it around as a value type, it's not like it's a big struct. i think he needs to - else he encapsulate the float into an struct which is then also on the heap (ast/whatever) nodex -> float nodey -> string nodez -> int nodew -> double etc. in this example a node can contain from n types values - how would you solve that? or better what is the smallest(maybe fastest) representation there need to be a queryable tree in the end - so there is a need to hold the values - yes he can copy by value - but into whom? in the end it will be an variant-like type (with members for each type) on heap - whichs is not that good because that will cost much more mem or something like an class FloatValue -> NodeValue -> Value oop-hierachy whichs also will get onto the heap i would try to use something like an base-types pool for all the small float,double,int,string etc values... and pointer to this pool - or just use the heap :)
Re: Immutability and other attributes, please review
Am 14.06.2012 15:26, schrieb Roman D. Boiko: But now, with everything immutable, I had to comment out several test cases. I cannot pass an immutable struct allocated on stack, into a method by reference, and then store a pointer to it, thats sounds very evil - with or without immutable how should that work anyway? because compiler says it is not an l-value. Should I allocate it on heap? Or get rid of functions taking parameter by ref, and use only those which take a pointer? i would use the heap and ref - else you need to copy, the pointer would also not work if your struct is still in the stack - or does the stack live long enough?
Re: void pointer syntax
>Am 16.05.2012 13:12, schrieb Stephen Jones: just throw aways your sensless void pointer or whatever idea - create a base interface or better base-class - everything else is just damn wrong btw: all oop widget sets for c++, java or else are haveing a widget base class that works like people telling you - try looking at Qt, Delphi-VLC, C#-Windows-Forms etc. they all got an TForm, TWidget, QWidget, Forms whatever baseclass all you need to do is to have a common interface - thats OOP all about, if you interested (or think you need to) get into implementation details of derived classe means you don't do OOP and then you need to do casting and all this strange looking stuff - but that will also happen in every other language around - because you do/think of OOP in a wrong way
Re: void pointer syntax
Am 14.05.2012 20:40, schrieb Stephen Jones: Ali Çehreli post got your answer - see the last example of the post news://news.digitalmars.com:119/jov3gn$2vtg$1...@digitalmars.com but first: try to understand how the base-class, interface stuff realy works - you will got the same problems in every other language like C++,Java,C#,Delphi,... you just do it the wrong way
Re: floats default to NaN... why?
Am 14.04.2012 07:48, schrieb F i L: On Saturday, 14 April 2012 at 05:19:38 UTC, dennis luehring wrote: Am 14.04.2012 06:00, schrieb F i L: struct Foo { int x, y;// ready for use. float z, w; // messes things up. float r = 0; // almost always... } how often in your code is 0 or 0.0 the real starting point? i can't think of any situation except counters or something where 0 is a proper start - and float 0.0 is in very very few cases a normal start - so whats your point? Every place that a structure property is designed to be mutated externally. Almost all Math structures, for instance. if a float or double is initalized with nan - all operations on them will result to nan - that is a very good sign for missing "proper" initialisation what does make float default to 0.0 better - does it just feel better?
Re: floats default to NaN... why?
Am 14.04.2012 06:00, schrieb F i L: struct Foo { int x, y;// ready for use. float z, w; // messes things up. float r = 0; // almost always... } how often in your code is 0 or 0.0 the real starting point? i can't think of any situation except counters or something where 0 is a proper start - and float 0.0 is in very very few cases a normal start - so whats your point?
Re: DMD/Windows: Inspect generated ASM?
ida 5.0 freeware http://www.hex-rays.com/products/ida/support/download_freeware.shtml Am 08.04.2012 14:42, schrieb Stefan: Hi all, Which is the most convenient way to have a look at the ASM code generated by Win-dmd? Unlike gdc, dmd it has no -S option, so I guess I will have to disassemble .obj files. Any good tools for this (link)? So far I only found old .obj tools from the 90s on the web... Thanks, Stefan
Re: parallel unzip in progress
Am 04.04.2012 08:31, schrieb Jay Norwood: On Tuesday, 3 April 2012 at 05:27:08 UTC, Jay Norwood wrote: .. So, to answer my own questions ... I placed the code below in a taskpool parallel foreach loop, where each am is an archive member. It is expanded, and the expanded data is written to a file. The original time info is coverted to SysTime using a localTime() tz timezone calculated outside the loop. Then the setTimes call updates the file timestamp in Windows. I just used the same system time st value for modification and access times. expand2(am); string destFilename = destName ~ am.name; std.file.write(destFilename,am.expandedData); SysTime st = DosFileTimeToSysTime(am.time, tz); std.file.setTimes(destFilename, st, st); The whole unzip, including restore of file modification times, completed in under 17 seconds for this 2GB expanded directory structure with some 39K files. 7zip took 55 seconds. This particular loop is currently excluding restore of times on directory entries, but I suppose I can restore the directory times after all the files have been expanded into the directory structure. great idea if its ok that the directory strucutre is in an inconsistent state on error - thats the main problem with parallel stuff - its faster if everything works ok - its hard to control the state if not
Re: Problem about lambda expressions
Am 27.03.2012 15:52, schrieb Tongzhou Li: Oh, I also tried: void seq_apply(Params..., Args...)(void delegate(Params) func, Args args) But I got a error: variadic template parameter must be last Does it mean that there can only be one variadic template parameter? How to fix it? Thanks just a question: how on earth should the compiler seperate your 2 variadic parameters??? t( a,b,c,x,y,z ) -> where Params Start/End, where Args magic?
Re: HelloWordl in Webserver
Am 17.03.2012 21:08, schrieb Xan: I dont' want to battle among languages, its maybe only a library battle > but I see that in Golang there is a beatiful solution to display HelloWorld program in web server [rosettacode.org/wiki/Hello_world/Web_server#Go]. no its creates and simple webserver and displays your Hello world > I'm convinced there is a D equivalent? i think you've got only pure stocket library around std.socket or something like that - maybe you find an implementation of an web-server in the tango library Can someone say what's its aspect? ??? Thanks in advance, Xan.
Re: Raw socket TCP/IP
Am 08.02.2012 19:35, schrieb Eyyub: BUMP, I really need help please ! Eyyub. what are you trying to archive? did you got an Ethernet-Frame+IP-Frame+(your replacement for tcp or udp) - or are your trying to change the tcp frame before sending? and if your using Windows: http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548%28v=vs.85%29.aspx here are two basic types of such raw sockets: The first type uses a known protocol type written in the IP header that is recognized by a Winsock service provider. An example of the first type of socket is a socket for the ICMP protocol (IP protocol type = 1) or the ICMPv6 protocol (IP procotol type = 58). The second type allows any protocol type to be specified. An example of the second type would be an experimental protocol that is not directly supported by the Winsock service provider such as the Stream Control Transmission Protocol (SCTP). Limitations on Raw Sockets On Windows 7, Windows Vista, Windows XP with Service Pack 2 (SP2), and Windows XP with Service Pack 3 (SP3), the ability to send traffic over raw sockets has been restricted in several ways: -TCP data cannot be sent over raw sockets. -UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address). These above restrictions do not apply to Windows Server 2008 R2, Windows Server 2008 , Windows Server 2003, or to versions of the operating system earlier than Windows XP with SP2.
why have protection attributes on/in interfaces abstract classes/methods no effect ouside a module?
why have protection attributes on/in interfaces and abstract classes/methods no effect outside a module? module types; private interface itest { private static void blub(); public void blub2(); private void blub3(); } private class test { protected abstract void blub4(); public abstract void blub5(); } --- module classes; import types; class A: itest { public static void blub(){} public void blub2(){} public void blub3(){} } class B: test { protected override void blub4(){} public override void blub5(){} } class C: test { public override void blub4(){} public override void blub5(){} } why is it allowed to use them in interface and abstract - and even check if there are no redundency like "private private" or something
Re: floating-WTF - Compiler-BUG with 64bit
Am 24.01.2012 19:13, schrieb Caligo: How did you compile it? As in my original post, it matters how you compile it. In this case (I'm on a 64-bit GNU/Linux system), compiling with '-inline' doesn't trigger the bug. im on win7 (64bit) - but the windows dmd2.057 isn't able to produce x64 code (is that correct?) it works with "dmd -inline floattest.d" and "dmd -debug floattest.d"
Re: floating-WTF - Compiler-BUG with 64bit
Am 24.01.2012 18:49, schrieb sclytrack: dmd 2.057 give this result under windows/32bit calculate1: 1.5 1.5 calculate2: 1.5 1.5 calculate3: 1.5 1.5 so its seems to be an x64 compiler bug Yes, I missed my lessons in clear communication. - + The complete source files. - import std.stdio; void calculate1(float a, float b) { float s1 = 1.0f - a; float s2 = a * b; writeln(s2); writeln(a * b); } void calculate2(float a, float b) { float s1 = 1.0 - a; float s2 = a * b; writeln(s2); writeln(a * b); } void calculate3(double a, double b) { double s1 = 1.0 - a; double s2 = a * b; writeln(s2); writeln(a * b); } int main() { writeln("calculate1:"); calculate1(0.75f,2.0f); writeln("calculate2:"); calculate2(0.75f,2.0f); writeln("calculate3:"); calculate3(0.75f,2.0f); return 0; } - + The complete output - calculate1: 1.5 1.5 calculate2: 0 1.5 calculate3: 1.5 1.5 - + Compiler - DMD64 D Compiler v2.057 Copyright (c) 1999-2011 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html Usage: This is from the downloaded zip file. I'm using eclipse to compile it. Added the -debug. - + Ubuntu 11.10 64 bit - uname -r 3.0.0-15-generic - + BEHAVIOUR - As for the behaviour on 32 bit. I wish somebody else would do it. :-) In the previous message here below is the assembly output of calculate2. Pay close attention to the cvtss2sd, the cvtsd2ss and the mulss. float s1 = 1.0 - a; float s2 = a * b; It converts the float a to double precision. then performs the s1 calculation. Then does the s2 calculation with the high precision a and the normal float b. Also it performs the "cvtsd2ss %xmm2,%xmm2" for no reason at all. As it is no longer used in the rest the code. - + objdump -S test1.o - <_D4main10calculate2FffZv>: 0: 55 push %rbp 1: 48 8b ecmov%rsp,%rbp 4: 48 83 ec 20 sub$0x20,%rsp 8: f3 0f 11 45 f0 movss %xmm0,-0x10(%rbp) d: f3 0f 11 4d f8 movss %xmm1,-0x8(%rbp) 12: 48 b8 00 00 00 00 00movabs $0x3ff0,%rax 19: 00 f0 3f 1c: 48 89 45 e0 mov%rax,-0x20(%rbp) 20: f2 0f 10 55 e0 movsd -0x20(%rbp),%xmm2 25: f3 0f 5a c9 cvtss2sd %xmm1,%xmm1 29: f2 0f 5c d1 subsd %xmm1,%xmm2 2d: f2 0f 5a d2 cvtsd2ss %xmm2,%xmm2 31: f3 0f 59 c8 mulss %xmm0,%xmm1 35: f3 0f 11 4d e8 movss %xmm1,-0x18(%rbp) 3a: f3 0f 10 45 e8 movss -0x18(%rbp),%xmm0 3f: e8 00 00 00 00 callq 44<_D4main10calculate2FffZv+0x44> 44: f3 0f 10 45 f8 movss -0x8(%rbp),%xmm0 49: f3 0f 10 4d f0 movss -0x10(%rbp),%xmm1 4e: f3 0f 59 c1 mulss %xmm1,%xmm0 52: e8 00 00 00 00 callq 57<_D4main10calculate2FffZv+0x57> 57: c9 leaveq 58: c3 retq 59: 90 nop 5a: 90 nop 5b: 90 nop I'm going to eat now. On 01/24/2012 05:01 PM, dennis luehring wrote: can you give us a complete out-of-the-box compileable example (with imports,main,etc.) with both examples the working/and nonworking does it work correct with dmd(32bit)? is this "calculate2" needed to reproduce the behavior? and what compiler did you test: dmd64, (dmd32?), ...? Am 24.01.2012 16:20, schrieb sclytrack: void calculate2(float a, float b) { float s1 = 1.0 - a; float s2 = a * b; writeln(s2); writeln(a * b); } Output: t*b= 0 t*b= 1.5 assume CS:.text._D4main10calculate2FffZv _D4main10calculate2FffZv: push RBP mov RBP,RSP sub RSP,020h movss -010h[RBP],XMM0 movss -8[RBP],XMM1 mov RAX,03FF0h mov -020h[RBP],RAX movsd XMM2,-020h[RBP] cvtss2sd XMM1,XMM1 subsd XMM2,XMM1 --conversion but xmm2 is no longer used cvtsd2ss XMM2,XMM2 --precision error multiplication mulss XMM1,XMM0 movss -018h[RBP],XMM1 movss XMM0,-018h[RBP] call _D3std5stdio14__T7writelnTfZ7writ
Re: floating-WTF
double works correct under dmd64, but float not? what is the behavior of dmd32 in this szenario?
Re: floating-WTF
can you give us a complete out-of-the-box compileable example (with imports,main,etc.) with both examples the working/and nonworking does it work correct with dmd(32bit)? is this "calculate2" needed to reproduce the behavior? and what compiler did you test: dmd64, (dmd32?), ...? Am 24.01.2012 16:20, schrieb sclytrack: void calculate2(float a, float b) { float s1 = 1.0 - a; float s2 = a * b; writeln(s2); writeln(a * b); } Output: t*b= 0 t*b= 1.5 assume CS:.text._D4main10calculate2FffZv _D4main10calculate2FffZv: pushRBP mov RBP,RSP sub RSP,020h movss -010h[RBP],XMM0 movss -8[RBP],XMM1 mov RAX,03FF0h mov -020h[RBP],RAX movsd XMM2,-020h[RBP] cvtss2sdXMM1,XMM1 subsd XMM2,XMM1 --conversion but xmm2 is no longer used cvtsd2ssXMM2,XMM2 --precision error multiplication mulss XMM1,XMM0 movss -018h[RBP],XMM1 movss XMM0,-018h[RBP] call _D3std5stdio14__T7writelnTfZ7writelnFfZv@PC32 movss XMM0,-8[RBP] movss XMM1,-010h[RBP] mulss XMM0,XMM1 call _D3std5stdio14__T7writelnTfZ7writelnFfZv@PC32 leave ret nop nop nop DMD64 D Compiler v2.057 Ubuntu 11.10
Re: associative arrays
Am 09.01.2012 22:08, schrieb Manfred Nowak: dennis luehring wrote: why is there an exception/error neeeded if missing? Exceptions or errors are not _needed_. Their existence stems from the modell under which the user of the operation _has_ to think about the operation, especially whether it is a:only the outcome of the operation or b:the amount of work to get to this outcome and maybe c:at runtime has to be known, whether the object exists. Jesse Phillips wrote: I have a lot of if(exists) remove() in my code As one can see, Jesse does not know, whether the object exists and has to ask, before he in fact removes the object, i.e. doubled access to the file, which may cause a slowdown. so your FileDelete would not return an FileDoesNotExists-Error? it isn't always clear what is "ok" to happen - there are million types of remove-like-semantic, an Jesse's scenario is one type of usage, which other type of remove allows silently non-remove-removes? STL? Python, etc. (how do others handle such cases) would it not help to better understand big code if the remove would be renamed to remove_existing or to add something like this?
Re: associative arrays
assert(key in aa); aa.remove(key); So, as far as I can tell, the current situation is more efficient, and it doesn't cost you any expressiveness. You can still have an exception thrown when remove fails if you use enforce before the call if you want an exception thrown when the element isn't there. but then it should be called optional_remove - because it "mabye" removes its like file_delete, DeleteFile (and all the others) on non existing files - why is there an exception/error neeeded if missing? the "maybe"-situation is not that often used in good code - because you can't find your errors if many routines would work like remove
Re: d2 file input performance
Am 26.08.2011 19:43, schrieb Christian Köstlin: Hi guys, i started the thread: http://stackoverflow.com/questions/7202710/fastest-way-of-reading-bytes-in-d2 on stackoverflow, because i ran into kind of a problem. i wanted to read data from a file (or even better from a stream, but lets stay with file), byte-by-byte. the whole thing was part of my protobuf implementation for d2, and there you have to look at each byte to read out the varints. i was very proud of my implementation until i benchmarked it first against java (ok ... i was a little slower than java) and then against c++ (ok ... this was a complete different game). after some optimizing i got better, but was still way slower than c++. so i started some small microbenchmarks regarding fileio: https://github.com/gizmomogwai/performance in c++, java and d2. could you help me improve on the d2 performance? i am sure, that i am missing something fundamental, because i thing it should be at least possible be equal or better than java. thanks in advance christian i would change the test szenario a little bit 1. use a ramdisk - so stuff like location on disk, fragmentation, driver speed will reducued down to a little bit of noise 2. make your szenario much bigger 3. would be interesting to see for example to cumulated every 1000 benchmarks-steps or something like that - to see caching coming in etc. running 10.000 times time for 1. 1000 steps xyzw time for 2. 1000 steps xyzw time for 3. 1000 steps xyzw time for 4. 1000 steps xyzw overall time ... xyz ...
Re: Any example of using these Special Tokens?
Am 25.05.2011 10:29, schrieb Matthew Ong: Hi, I am not able make use of these 3 special tokens to print something. writefln("gshared: %s",__gshared); writefln("thread: %s",__thread); writefln("traits: %s",__traits); rc\Sample.d(128): expression expected, not '__gshared' src\Sample.d(129): expression expected, not '__thread' src\Sample.d(130): found ')' when expecting '(' src\Sample.d(130): __traits(identifier, args...) expected src\Sample.d(132): found '}' when expecting ',' src\Sample.d(146): expression expected, not 'EOF' src\Sample.d(146): found 'EOF' when expecting ',' src\Sample.d(146): expression expected, not 'EOF' src\Sample.d(146): found 'EOF' when expecting ',' src\Sample.d(146): expression expected, not 'EOF' Would some like to show me how this is done?? google is your friend, search for "__traits d" http://www.digitalmars.com/d/2.0/traits.html
Re: Any example of using these Special Tokens?
Am 25.05.2011 12:42, schrieb Matthew Ong: On 5/25/2011 5:45 PM, bearophile wrote: Matthew Ong: I am not able make use of these 3 special tokens to print something. writefln("gshared: %s",__gshared); writefln("thread: %s",__thread); writefln("traits: %s",__traits); They are keywords, so it's like writing: writefln("traits: %s", for); Would some like to show me how this is done?? What do you want to do? Bye, bearophile Looking at if they are run time related debug variables, perhaps consider using them within a logging api. and what is the benefit over using libary functions? how many of this special vars will come (and pollute the global namespace...)
Re: How to search news group?
Am 12.05.2011 15:24, schrieb Matthew Ong: Hi D Forum Admin, I am using the webbase interface for the forum. How to do forum text search instead of browsing over them one by one? Matthew Ong use thunderbird as newsclient
Re: Setting thread priority
Am 06.02.2011 02:58, schrieb Peter Alexander: How do you set the priority of a thread, or otherwise control how much CPU time it gets? depends on operating system - on windows: set the priority to high does not help if your system isn't under pressure ...
Re: Nested function declarations
They're useful for testing: unittest { int foo(); static assert (is(ReturnType!foo == int)); } and else? is it worth?
Re: about float & double
Is there somewhere a (clear) doc about float/double internals? Some more particuliar questions: What is the internal bit layout? (mantissa, sign, exponent) Can I assume the "integral range" is [-2^(m-1) .. 2^�m-1)-1], where m is the number of mantissa bits? What are the values used to represent thingies like NaNs, inf, error? (Or are there not represented as values?) How would you get a float's integral and fractional parts without performing arithmetic? (I think at bit ops, indeed) Wikipedia is very informative and the phobos math implementation is a very good source for the bit ops stuff http://www.dsource.org/projects/phobos/browser/trunk/phobos/std/math.d
Re: associative array of associative arrays.
Am 13.08.2010 01:17, schrieb dcoder: string[string][string] leaders or try using alias to "see" the light alias string[string] city_info; city_info[string] leaders; Hello. How do you declare and initialize a map that looks like the following: Name => [ Personal Info] Where personal info is type string[string]. I can't get this to compile. I'm wondering what I am doing wrong: import std.stdio; void main() { int[string] helloworld = [ "Hello":0, "World":1 ]; foreach( k,v;helloworld) { writefln( "%s -> %s", k, v); } writefln( "helloworld type: %s", typeid(helloworld)); string[string] table = [ "City":"Boston", "Title":"Vice President" ]; foreach( k, v; table) { writefln( "%s: %s", k, v); } // Here's the problem: string[string[string]] leaders = [ "Obama":["City":"DC", "Title":"ThePrez"], "Cameron":["City":"London", "Title":"DaPrimeMinista"]]; foreach( k, v; leaders) { writefln( "first foreach type: %s", typeid(v)); writefln( "Person: %s", k); foreach( kk, vv; v) { writefln( "\t%s\t%s", kk, vv); } } return; } Here's the output: $ dmd AssocArray.d AssocArray.d(25): Error: Integer constant expression expected instead of "City" AssocArray.d(25): Error: Integer constant expression expected instead of "Title" AssocArray.d(25): Error: Integer constant expression expected instead of "City" AssocArray.d(25): Error: Integer constant expression expected instead of "Title" AssocArray.d(24): Error: not an associative array initializer $ dmd --help Digital Mars D Compiler v2.047 Copyright (c) 1999-2010 by Digital Mars written by Walter Bright Documentation: http://www.digitalmars.com/d/2.0/index.html thanks dcoder
Re: Why assert is in the language?
Am 22.06.2010 23:07, schrieb Tomek Sowiñski: Yes, why? It could be implemented in object.d in a similar fashion as std.contracts.enforce. Does it do anything special that a library function couldn't? Tomek what about static assert?
Re: delegates with C linkage
Am 06.06.2010 17:30, schrieb Zarathustra: are delegats part of the ABI, i can't find a delegat calling scheme in the ABI-Description - should this be in EAX, as last/first part on stack, ECX? The delegates are called by exactly same way as any other member function. Put ptr = 'this'(context pointer) to EAX and call funcptr (pointer to function). If I remember well, the 'this' pointer is passed to functions by ECX in C++. The delegate structure layout is described in ABI. ABI, disassembler and trail-end-error method will give you (and me too, because I still need to explore many things) an answer to many questions. ok and it would be nice to have an clear description of this ABI+disasm trial-error-reusults in the ABI-Description - i think your example is needed to show walter the missing parts of the ABI-Doc
Re: delegates with C linkage
Am 06.06.2010 11:33, schrieb Simen kjaeraas: Also, pointers to delegates can be passed to C-linkage functions. A delegate is nothing but a struct, and as such there is no reason for it not to be passable to a C-linkage function. my fault - yes its possible to use delegates in non D but delegat-struct knowing languages (and a small pice of special calling code), sorry Zarathrustra i missed the point of your post in whole >I say this is a bug. me too are delegats part of the ABI, i can't find a delegat calling scheme in the ABI-Description - should this be in EAX, as last/first part on stack, ECX? wouldn't it be nice to have an complete call/use D features through c example around?
Re: delegates with C linkage
Am 05.06.2010 16:03, schrieb dennis luehring: Am 05.06.2010 15:42, schrieb Zarathustra: only with static methods - a real delegate needs the this-pointer in a register (not on the stack), thats the main difference between function ptr and delegates, thats why you can't use a (non static) method on for example the win-api callbacks, because the caller don't know your object gcc: __attribute__((regparm (1))) put_first_paramerter_to_eax(d_object this){...} __attribute__((regparm (1))) - puts the first function parameter to EAX. ok so your using gcc and some "extensions" but that will help on the caller side (you using gcc?) but D still won't accept an delegat in an extern C because this type does not exists in the C world btw: can show us code where you do this and it works - why don't you use your working code as an example?
Re: delegates with C linkage
Am 05.06.2010 15:42, schrieb Zarathustra: only with static methods - a real delegate needs the this-pointer in a register (not on the stack), thats the main difference between function ptr and delegates, thats why you can't use a (non static) method on for example the win-api callbacks, because the caller don't know your object gcc: __attribute__((regparm (1))) put_first_paramerter_to_eax(d_object this){...} __attribute__((regparm (1))) - puts the first function parameter to EAX. ok so your using gcc and some "extensions"
Re: delegates with C linkage
Am 05.06.2010 13:33, schrieb Zarathustra: Secondly, I'm not sure if you can pass delegates to a C function. C code wouldn't understand delegates. They are not the same as function pointers. I suggest you use function pointers instead, paying attention to linkage. Of course It is possible, because I have done it and it works pretty well. only with static methods - a real delegate needs the this-pointer in a register (not on the stack), thats the main difference between function ptr and delegates, thats why you can't use a (non static) method on for example the win-api callbacks, because the caller don't know your object
Re: Factory class
void main() { auto pizza = PizzaFactory.factory(); pizza.doSome(); // OK pizza.doSomeA(); // error: IPizza.doSomeA() not found } you interface has only doSome() and that is what factory returns and for all others: factories and cast don't belong together you interface should fit your overall needs