Thanks Jonathan, that cleared things up for me.
Send Digitalmars-d-learn mailing list submissions to
digitalmars-d-learn@puremagic.com
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.puremagic.com/cgi-bin/mailman/listinfo/digitalmars-d-learn
or, via email, send a message with subject or body 'help' to
digitalmars-d-learn-request@puremagic.com
You can reach the person managing the list at
digitalmars-d-learn-owner@puremagic.com
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Digitalmars-d-learn digest..."
Today's Topics:
1. dmd vs rdmd (Joshua Niehus)
2. Re: dmd vs rdmd (Jonathan M Davis)
3. Re: dmd vs rdmd (Andrej Mitrovic)
4. char[] to string (Jonathan Sternberg)
5. Re: char[] to string (Jonathan M Davis)
6. Re: DMD Backend: Deciding instructions to use/avoid?
(Nick Sabalausky)
7. Re: char[] to string (bearophile)
----------------------------------------------------------------------
Message: 1
Date: Fri, 10 Jun 2011 14:28:41 -0700
From: Joshua Niehus <jm.niehus@gmail.com>
To: digitalmars-d-learn@puremagic.com
Subject: dmd vs rdmd
Message-ID: <BANLkTi=TYnN+UuxCr8wj8UwFRjS=iVzM3Q@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
I am trying to compile code which is composed of two modules (in the same
directory):
main.d
foo.d
foo.d just declares a class Foo which has a string variable "bar" which i
set to "hello" and main.d just prints bar's value to the console:
// --------- main.d -----------
import std.stdio, foo;
void main() {
Foo f = new Foo;
writeln(f.bar);
}
When i attempt to compile main.d via:
$dmd main.d
I get undefined symbol errors.
But when I run:
$rdmd main.d
it works as expected.
The only way I could get main.d to compile with just dmd was to compile foo
as a lib first and then compile main.d and passing the foo.a file as an
argument:
$dmd -lib foo.d
$dmd main.d foo.a
Is this normal?
I got the impression from TDPL (Alexandrescu) that the dmd compiler would
automatically search the root directory, find foo.d, work its magic, and
create all the symbols that were defined in foo.d for main.d to compile...
Thanks,
Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110610/dccf485f/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 10 Jun 2011 21:50:37 +0000
From: "Jonathan M Davis" <jmdavisProg@gmx.com>
To: "digitalmars.D.learn" <digitalmars-d-learn@puremagic.com>
Subject: Re: dmd vs rdmd
Message-ID: <20110610215037.56570@gmx.com>
Content-Type: text/plain; charset="utf-8"
On 2011-06-10 14:28, Joshua Niehus wrote:
> Hello,
>
> I am trying to compile code which is composed of two modules (in the same
> directory):
>
> main.d
> foo.d
>
> foo.d just declares a class Foo which has a string variable "bar" which i
> set to "hello" and main.d just prints bar's value to the console:
>
> // --------- main.d -----------
> import std.stdio, foo;
>
> void main() {
> Foo f = new Foo;
> writeln(f.bar);
> }
>
> When i attempt to compile main.d via:
> $dmd main.d
> I get undefined symbol errors.
>
> But when I run:
> $rdmd main.d
> it works as expected.
>
> The only way I could get main.d to compile with just dmd was to compile foo
> as a lib first and then compile main.d and passing the foo.a file as an
> argument:
> $dmd -lib foo.d
> $dmd main.d foo.a
>
> Is this normal?
> I got the impression from TDPL (Alexandrescu) that the dmd compiler would
> automatically search the root directory, find foo.d, work its magic, and
> create all the symbols that were defined in foo.d for main.d to compile...
With dmd, you must list every file that you're compiling. The only exceptions
are that when dealing with libraries, dmd to have the root directory where the
source is passed to -I, and it needs to have the root directory where the
library is given with -L and -l with the library name (or just the library
directly if you don't want it to search for the library). It's like gcc and
dmc in that respect. It does nothing extra to track down files to compile for
you. It'll find the source for importing thanks to -I, but it won't compile
it. You must still compile it. You don't normally need -I or -L however,
because dmd.conf (or sc.ini on Windows) already adds the appropriate flags for
Phobos for you. You only need too specify them yourself when using other
libraries.
rdmd does extra magic to automatically track down all of the files that main.d
imports and compile them. dmd doesn't do that.
- Jonathan M Davis
------------------------------
Message: 3
Date: Sat, 11 Jun 2011 01:08:50 +0200
From: Andrej Mitrovic <andrej.mitrovich@gmail.com>
To: "digitalmars.D.learn" <digitalmars-d-learn@puremagic.com>
Subject: Re: dmd vs rdmd
Message-ID: <BANLkTimH88skMm0DEa7h1JLuGhZaJ9XJqw@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Perhaps -L is just a linux feature, on Windows it only passes options
to Optlink, and passing directories won't add them to search paths for
library files.
E.g. if I have:
main.d
foo/test.d
foo/test.lib <- compiled as a library
and try to invoke:
dmd main.d -I.\foo\ test.lib -L.\foo\
Optlink won't find the lib file:
Warning 2: File Not Found foo.lib
I always have to specify the full path to the lib file, e.g.:
dmd main.d -I.\test2\ .\test2\foo.lib
------------------------------
Message: 4
Date: Sat, 11 Jun 2011 02:56:19 +0000 (UTC)
From: Jonathan Sternberg <jonathansternberg@gmail.com>
To: digitalmars-d-learn@puremagic.com
Subject: char[] to string
Message-ID: <isulgj$1efp$1@digitalmars.com>
Content-Type: text/plain; charset="utf-8"
Why doesn't this work?
import std.stdio;
string copy_string(char [] input)
{
return input.dup;
}
int main()
{
char [] buf = ['h', 'e', 'l', 'l', 'o'];
writeln( copy_string(buf) );
}
I want to do something more complex. In my code, I want to have a dynamic
array that I can append stuff into and then return it as a string. In C++, a
non-const variable can be implicitly converted into a const. I know string is
an alias for const char. Is there a reason why it won't implicitly convert it?
I hesitate to use cast for this type of thing as it probably indicates I'm
doing something fundamentally wrong as I'm just starting to learn the language.
------------------------------
Message: 5
Date: Fri, 10 Jun 2011 21:32:44 -0700
From: Jonathan M Davis <jmdavisProg@gmx.com>
To: "digitalmars.D.learn" <digitalmars-d-learn@puremagic.com>
Subject: Re: char[] to string
Message-ID: <201106102132.44286.jmdavisProg@gmx.com>
Content-Type: Text/Plain; charset="us-ascii"
On 2011-06-10 19:56, Jonathan Sternberg wrote:
> Why doesn't this work?
>
> import std.stdio;
>
> string copy_string(char [] input)
> {
> return input.dup;
> }
>
> int main()
> {
> char [] buf = ['h', 'e', 'l', 'l', 'o'];
> writeln( copy_string(buf) );
> }
>
> I want to do something more complex. In my code, I want to have a dynamic
> array that I can append stuff into and then return it as a string. In C++,
> a non-const variable can be implicitly converted into a const. I know
> string is an alias for const char. Is there a reason why it won't
> implicitly convert it?
>
> I hesitate to use cast for this type of thing as it probably indicates I'm
> doing something fundamentally wrong as I'm just starting to learn the
> language.
string is an alias for immutable(char)[]. The elements of a string can never
be altered. dup returns a mutable copy of a string (not const, not immutable).
idup returns an immutable copy. So, in this case you want idup, not dup. Even
better though, would be to use std.conv.to - e.g. to!string(input). This will
convert input to a string, but it has the advantage that if input is already a
string, then it'll just return the string rather than making another copy like
idup would.
- Jonathan M Davis
------------------------------
Message: 6
Date: Sat, 11 Jun 2011 03:11:07 -0400
From: "Nick Sabalausky" <a@a.a>
To: digitalmars-d-learn@puremagic.com
Subject: Re: DMD Backend: Deciding instructions to use/avoid?
Message-ID: <isv4mh$2a0v$1@digitalmars.com>
"Andrew Wiley" <wiley.andrew.j@gmail.com> wrote in message
news:mailman.762.1307693296.14074.digitalmars-d-learn@puremagic.com...
> On Thu, Jun 9, 2011 at 5:58 PM, Nick Sabalausky <a@a.a> wrote:
>
>> "Bernard Helyer" <b.helyer@gmail.com> wrote in message
>> news:isdgdc$m3a$1@digitalmars.com...
>> > If you run the program in GDB, can you disassemble when the error is
>> > given? That may give you the instruction the kernel is assasinating
>> > your
>> > process for.
>>
>> I can try that if anyone can help walk me through it or at least point me
>> to
>> a good beginner's tutorial for gdb. I never use commandline debuggers,
>> and
>> I've never even touched gdb, so I don't have the slightest clue how to
>> use
>> it.
>>
>>
>> The short version is to run `gdb yourapp` which will get you into the GDB
> shell. Then `run` to actually start the app. It will halt and return to
> the
> shell when it hits the bad instruction, and you should type `disass` to
> view
> the assembly code of the current function. There will be a pointer (->, I
> think) pointing to the current instruction in the listing.
> You can find GDB basics at http://www.cs.cmu.edu/~gilpin/tutorial/
> although
> that tutorial doesn't include `disass`. I mostly learned it by firing it
> up
> and typing `help` :D
>
Thanks. This is what I get:
$ gdb ./dvm-0.2.0-linux-32
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/nick/dev/d/tool/dvm-0.2.0-linux-32...(no
debugging symbols found)...done.
(gdb) run
Starting program: /home/nick/dev/d/tool/dvm-0.2.0-linux-32
[Thread debugging using libthread_db enabled]
Program received signal SIGILL, Illegal instruction.
0x080bccdb in
_D5tango4core4sync6Atomic31__T13memoryBarrierVb1Vb0Vi0Vb0Z13memoryBarrierFZv
()
(gdb) disass
Dump of assembler code for function
_D5tango4core4sync6Atomic31__T13memoryBarrierVb1Vb0Vi0Vb0Z13memoryBarrierFZv:
0x080bccd8 <+0>: push %ebp
0x080bccd9 <+1>: mov %esp,%ebp
=> 0x080bccdb <+3>: lfence
0x080bccde <+6>: pop %ebp
0x080bccdf <+7>: ret
End of assembler dump.
(gdb)
So apperently it's a memory fence instruction. I don't have a clue what my
CPU supports in that area. Oh, and apperently it's inside Tango, so maybe
I'll bring this up over there. But I have no idea if that's something that
Tango has in common with druntime or not.
------------------------------
Message: 7
Date: Sat, 11 Jun 2011 08:12:51 -0400
From: bearophile <bearophileHUGS@lycos.com>
To: digitalmars-d-learn@puremagic.com
Subject: Re: char[] to string
Message-ID: <isvm43$bjo$1@digitalmars.com>
Content-Type: text/plain
Jonathan M Davis:
> Even better though, would be to use std.conv.to - e.g. to!string(input). This will
> convert input to a string, but it has the advantage that if input is already a
> string, then it'll just return the string rather than making another copy like
> idup would.
I didn't know this. Isn't it very good to give this bit of intelligence to idup too?
Bye,
bearophile
------------------------------
_______________________________________________
Digitalmars-d-learn mailing list
Digitalmars-d-learn@puremagic.com
http://lists.puremagic.com/cgi-bin/mailman/listinfo/digitalmars-d-learn
End of Digitalmars-d-learn Digest, Vol 65, Issue 26
***************************************************