Re: is there a cleaner way to new a static sized array?

2010-02-24 Thread FeepingCreature
On 24.02.2010 22:19, BCS wrote: > Hello FeepingCreature, > >> On 24.02.2010 05:16, BCS wrote: >> >>> I need a function that works like the following: >>> T* New(T)() { return new T; } >>> But that also works with static arrays: >>> auto i = New!(int)(); auto a = New!(int[27])()

How to read from an input stream generically?

2010-02-24 Thread Ali Çehreli
What can I use instead of the din.readf line below to be able to read any type in that generic function? import std.cstream; struct MyType {} void generic(T)() { T var; dout.writef("Please enter a value of type %s: ", T.stringof); din.readf(&var); // <-- Runtime ERROR for MyType

Re: Simple Socket Server Code

2010-02-24 Thread sybrandy
On 02/24/2010 09:00 AM, daoryn wrote: Check the "samples" dir inside the dmd instalation folder. Theres a sample there named "listener.d" that shows how to use D sockets. If you're using DMD2, the listener.d file is broken. You'll have to convert it into D2 yourself. I actually did look at tha

Re: When is array-to-array cast legal, and what does actually happen?

2010-02-24 Thread bearophile
Daniel Keep: > [1] Except for int<->float. Oh, and objects. Really, this is one thing > I could just about strangle K&R for: conflating value-preserving, > non-value-preserving *AND* unsafe conversions all into a single > construct. Walter, gets slapped with a fish for not putting a bullet in >

Re: is there a cleaner way to new a static sized array?

2010-02-24 Thread BCS
Hello Daoryn, BCS Wrote: I need a function that works like the following: T* New(T)() { return new T; } But that also works with static arrays: auto i = New!(int)(); auto a = New!(int[27])(); The cleanest solution I can think of is: T* New(T)() { return (new T[1]).ptr; } but that s

Re: is there a cleaner way to new a static sized array?

2010-02-24 Thread BCS
Hello FeepingCreature, On 24.02.2010 05:16, BCS wrote: I need a function that works like the following: T* New(T)() { return new T; } But that also works with static arrays: auto i = New!(int)(); auto a = New!(int[27])(); The cleanest solution I can think of is: T* New(T)() { return (

Re: exceptions

2010-02-24 Thread Robert Clipsham
On 24/02/10 20:20, Ellery Newcomer wrote: Oooh! nice trick! Ah, it's '_d_th...@4' and quotes help. Yahoo! Do I need to do anything special to get stack tracing to work? when I try to compile a simple program it barfs on me and gives undefined reference to `dladdr' from import tango.core.tool

Accessing the symbol table of a mach-o file

2010-02-24 Thread Jacob Carlborg
I'm trying to access the symbol table of a mach-o file. I've managed to access the symbol table but I have two problems: 1. It seems I can't access the whole symbol table if I compare my output to the output of nm. For example, I have a global struct in the file I'm examining which doesn't sho

Re: exceptions

2010-02-24 Thread Ellery Newcomer
On 02/24/2010 12:37 PM, Robert Clipsham wrote: On 24/02/10 17:51, Ellery Newcomer wrote: import tango.core.tools.TraceExceptions; If you want to use gdb then type 'b _d_throw_exception' (or 'b _d_throw' for dmd) before you run your app. This will break on every exception thrown, so yo

Re: Using C function in Tango - Simple solution?

2010-02-24 Thread Fabian Classen
Am Wed, 24 Feb 2010 19:58:59 + schrieb Robert Clipsham: > On 24/02/10 19:46, Fabian Classen wrote: >> Hi >> I am new in D. >> I've the following problem. I want to use a old function out of the C >> programming language. I'm using D, with the dmd compiler, and the Tango >> lib. My "dirty" solu

Re: Using C function in Tango - Simple solution?

2010-02-24 Thread Robert Clipsham
On 24/02/10 19:46, Fabian Classen wrote: Hi I am new in D. I've the following problem. I want to use a old function out of the C programming language. I'm using D, with the dmd compiler, and the Tango lib. My "dirty" solution is the following: version (Tango) extern (C) int getchar(); void mai

Using C function in Tango - Simple solution?

2010-02-24 Thread Fabian Classen
Hi I am new in D. I've the following problem. I want to use a old function out of the C programming language. I'm using D, with the dmd compiler, and the Tango lib. My "dirty" solution is the following: version (Tango) extern (C) int getchar(); void main() { char quit = '\0'; w

Re: exceptions

2010-02-24 Thread Robert Clipsham
On 24/02/10 17:51, Ellery Newcomer wrote: import tango.core.tools.TraceExceptions; If you want to use gdb then type 'b _d_throw_exception' (or 'b _d_throw' for dmd) before you run your app. This will break on every exception thrown, so you may have to hit 'c' a few times to continue at

Re: exceptions

2010-02-24 Thread Ellery Newcomer
On 02/24/2010 10:35 AM, Robert Clipsham wrote: On 24/02/10 15:21, Ellery Newcomer wrote: On 02/24/2010 09:00 AM, Daniel Keep wrote: Ellery Newcomer wrote: On 02/24/2010 03:10 AM, bearophile wrote: Ellery Newcomer: Okay, does anyone know a good way to figure out where something like this is

Re: exceptions

2010-02-24 Thread Robert Clipsham
On 24/02/10 15:21, Ellery Newcomer wrote: On 02/24/2010 09:00 AM, Daniel Keep wrote: Ellery Newcomer wrote: On 02/24/2010 03:10 AM, bearophile wrote: Ellery Newcomer: Okay, does anyone know a good way to figure out where something like this is coming from: object.Exception: lengths don't ma

Re: is there a cleaner way to new a static sized array?

2010-02-24 Thread FeepingCreature
On 24.02.2010 05:16, BCS wrote: > I need a function that works like the following: > >> T* New(T)() { return new T; } > > But that also works with static arrays: > >> auto i = New!(int)(); >> auto a = New!(int[27])(); > > The cleanest solution I can think of is: > >> T* New(T)() { return (new

Re: exceptions

2010-02-24 Thread bearophile
Ellery Newcomer: > I want line numbers http://d.puremagic.com/issues/show_bug.cgi?id=3851 Bye, bearophile

Re: exceptions

2010-02-24 Thread bearophile
Ellery Newcomer: > I want line numbers You can file a low priority bug request on this then. Bye, bearophile

Re: exceptions

2010-02-24 Thread Ellery Newcomer
On 02/24/2010 09:00 AM, Daniel Keep wrote: Ellery Newcomer wrote: On 02/24/2010 03:10 AM, bearophile wrote: Ellery Newcomer: Okay, does anyone know a good way to figure out where something like this is coming from: object.Exception: lengths don't match for array copy void main() { au

Re: is there a cleaner way to new a static sized array?

2010-02-24 Thread daoryn
BCS Wrote: > I need a function that works like the following: > > > T* New(T)() { return new T; } > > But that also works with static arrays: > > > auto i = New!(int)(); > > auto a = New!(int[27])(); > > The cleanest solution I can think of is: > > > T* New(T)() { return (new T[1]).ptr; } >

Re: exceptions

2010-02-24 Thread Daniel Keep
Ellery Newcomer wrote: > On 02/24/2010 03:10 AM, bearophile wrote: >> Ellery Newcomer: >>> Okay, does anyone know a good way to figure out where something like >>> this is coming from: >>> object.Exception: lengths don't match for array copy >> >> void main() { >> auto a1 = new int[5]; >>

Re: Simple Socket Server Code

2010-02-24 Thread daoryn
sybrandy Wrote: > All, > > Does anyone know where I can get a simple example of writing a server in > D? Just a stupid little echo server would be fine. I'm trying to write > one myself, but for some reason it doesn't seem to be accepting any > connections. I figure it's something stupidly

Re: exceptions

2010-02-24 Thread Ellery Newcomer
On 02/24/2010 03:10 AM, bearophile wrote: Ellery Newcomer: Okay, does anyone know a good way to figure out where something like this is coming from: object.Exception: lengths don't match for array copy void main() { auto a1 = new int[5]; auto a2 = new int[4]; a1[] = a2; } Bye,

Re: exceptions

2010-02-24 Thread bearophile
Ellery Newcomer: > Okay, does anyone know a good way to figure out where something like > this is coming from: > object.Exception: lengths don't match for array copy void main() { auto a1 = new int[5]; auto a2 = new int[4]; a1[] = a2; } Bye, bearophile