Re: C Bitfields in D
On 08/12/2010 02:23, Simen kjaeraas wrote: Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Cool! But, when is ctod.exe coming out? :p That should have been cpptod. ;) As soon as you write it. See d.announce SWIG for D :)
use of Class Invariants
At the moment most of my public member functions are littered with these kind of in-out clauses. in{ assert(wellformed, toString); } out{ assert(wellformed, toString); } They just beg for invariants, I though.. But invariants don't report the location of failure of contract, only the location of failure within the invariant. This seems kind of limiting. Am I missing something here?
undefined identifier getch()
Hey guys, I'm writing a console based tool for windows. To receive the users input, I try to use getch() but the compiler always says Error: undefined identifier getch. When I use getchar() it compiles successfully, but getchar() doesn't returns after a single input. Is there any equivalent version in D for getch? Thanks regards...
Re: use of Class Invariants
On Wednesday 08 December 2010 00:22:23 %u wrote: At the moment most of my public member functions are littered with these kind of in-out clauses. in{ assert(wellformed, toString); } out{ assert(wellformed, toString); } They just beg for invariants, I though.. But invariants don't report the location of failure of contract, only the location of failure within the invariant. This seems kind of limiting. Am I missing something here? If an invariant fails, it throws an AssertError which will give you stack trace. That stack trace should include which function called the invariant. So, it _does_ tell you which function resulted in the invariant failing. - Jonathan M Davis
Re: undefined identifier getch()
On Wed, 08 Dec 2010 06:06:18 -0500, Nrgyzer nrgy...@gmail.com wrote: Hey guys, I'm writing a console based tool for windows. To receive the users input, I try to use getch() but the compiler always says Error: undefined identifier getch. When I use getchar() it compiles successfully, but getchar() doesn't returns after a single input. Is there any equivalent version in D for getch? Thanks regards... Just a note, dmd on windows does not use Microsoft's C library, it uses Digital Mars'. Therefore, any C functions that are not part of the platform SDK are not available in D. To see what DMC supports, look here: http://www.digitalmars.com/rtl/rtl.html -Steve
Re: undefined identifier getch()
Okay, but what function can I use to get the pressed key? kbhit/_kbhit seems to do what I want, but hwo can I use it in D? I always get the error, that kbhit (or similar functions) are not available. import std.stdio; import std.c.stdlib; import std.c.windows.windows; void main(string[] args) { kbhit(); _kbhit(); }
Re: undefined identifier getch()
On Wed, 08 Dec 2010 08:57:40 -0500, Steven Schveighoffer schvei...@yahoo.com wrote: extern(C) int kbhit(void); Um... sorry, D doesn't support void args (copy-paste problem): extern(C) int kbhit(); -Steve
Re: undefined identifier getch()
Great, thanks :)
Re: undefined identifier getch()
On 08/12/2010 11:06, Nrgyzer wrote: Hey guys, I'm writing a console based tool for windows. To receive the users input, I try to use getch() but the compiler always says Error: undefined identifier getch. When I use getchar() it compiles successfully, but getchar() doesn't returns after a single input. Under DMD 1, getch is declared in std.c.stdio. So import that. Under DMD 2, I don't know why it isn't there. But you just need to add this declaration: extern (C) int getch(); Is there any equivalent version in D for getch? D doesn't have its own API for console operations besides stdin/stdout/stderr stuff. I guess it wasn't worth creating one partly because it would be a load of pointless wrappers around C functions, and partly because in these days where everyone uses GUI-based software they're not used as much. Stewart.
Re: undefined identifier getch()
On 08/12/2010 13:25, Nrgyzer wrote: Okay, but what function can I use to get the pressed key? kbhit/_kbhit seems to do what I want, but hwo can I use it in D? I always get the error, that kbhit (or similar functions) are not available. snip kbhit just tests whether there's a keystroke waiting in the keyboard buffer. It doesn't identify the key pressed. If you want to wait for the user to press a key, use getch. If you want to test whether the user has pressed a key, use kbhit, then use getch to determine what key was pressed. For some reason, this seems to work reliably only on ASCII character keys, backspace, tab and carriage return. But this might be partly due to bugs in the DM implementation. Stewart.
Re: use of Class Invariants
== Quote from Jonathan M Davis (jmdavisp...@gmx.com)'s article On Wednesday 08 December 2010 00:22:23 %u wrote: At the moment most of my public member functions are littered with these kind of in-out clauses. in{ assert(wellformed, toString); } out{ assert(wellformed, toString); } They just beg for invariants, I though.. But invariants don't report the location of failure of contract, only the location of failure within the invariant. This seems kind of limiting. Am I missing something here? If an invariant fails, it throws an AssertError which will give you stack trace. That stack trace should include which function called the invariant. So, it _does_ tell you which function resulted in the invariant failing. - Jonathan M Davis That is what I am missing, a stack trace. How do I see a stack trace? dmd1(win)
Re: use of Class Invariants
%u Wrote: That is what I am missing, a stack trace. How do I see a stack trace? dmd1(win) I don't think the Windows stack trace is compete yet. Works in Linux.
Re: use of Class Invariants
That is what I am missing, a stack trace. How do I see a stack trace? dmd1(win) Well tango includes stack traces if you import the right module. For D2/Win use http://3d.benjamin-thaut.de/?p=15
Re: A CTFE Segfault (with explanation, but I'm not sure what the fix
On 21/11/10 22:39, bearophile wrote: Gareth Charnock: struct LeafType { string Compile_not_ovloaded() { return expression; } }; Note that D structs don't require the ending semicolon, so in practice it is not used. And in D method names start with a lower case. Bye, bearophile Okay, but this was completely experimental code unlikely to see the light of day. I like to put the semicolon after the struct to keep in the habit (otherwise when I use C++ I start forgetting). The _not_ovloaded bit was to check the bug wasn't anything to do with overloading (it wasn't).