I'm sorry, what I meant was "how to interface to C code". Sorry
for writing it in a bad way.
Do I just declare the C code as extern and then link together
with the C .lib/.o/.so file? (I'm in Ubuntu)
What about the stuff that is in header files?
Thank you very much :)
I like the "you are done :)" approach!
How can I do that?
Why not list.remove(x); like in STL?
On Wednesday, 27 June 2012 at 09:52:14 UTC, Tobias Pankrath wrote:
On Wednesday, 27 June 2012 at 09:37:01 UTC, Minas Mina wrote:
How can I do that?
Why not list.remove(x); like in STL?
std.container encodes the complexity of operations in the
method names. There is no way to remove a range
Thank you for your reply. Yes, std.container really sucks.
Anyway, I made my program using C++ and STL
Doesn't Andrei plan to do something about this module?
I have been "playing" latetly with std.concurrency and
core.thread. I like both, but they are entirely different
approaches to concurrency.
std.concurrency: Uses message passing. Does not allow passing of
mutable types.
core.thread: Essentially the same as the approach taken by Java.
1) Is o
You all helped, thank you :)
I will read the concurrency part tomorrow!
On Wednesday, 27 June 2012 at 23:50:17 UTC, Ali Çehreli wrote:
On 06/27/2012 04:05 PM, Adam Burton wrote:
>> For example I would like to
>> have a thread calculate the sum of the first half of an array
>> while another thread would calculate the other half, and I
could
>> add the two results at
I'm fairly new to D, but I have been using C++ for a while now
(about 5 years, selftaught).
From what I have learned, const in C++ is inconsistent.
For example:
int main()
{
const int x = 0; // could be placed in ROM because it's known
at compile time
}
void f(int x)
{
const int y = x
On Thursday, 12 July 2012 at 14:42:17 UTC, Ali Çehreli wrote:
On 07/12/2012 07:13 AM, Minas wrote:
Thanks a lot!
So what is the problem with (logical)const? Is it needed that
much? And why some methods (toString(), toHash()) HAVE to be
const? I mean, what's the problem if they aren't?
Here is
I guess it's because you have an array of constants (immutables).
The array is not immutable though. I could be wrong, I'm not an
expert or D syntax :)
I'm want to "play" a bit with thread syncronization...
So this is a (big) part of my code. The other is the imports, the
thread starting and the printing of x.
shared int x;
shared Semaphore sema;
void main(string[] args)
{
auto t1 = new Thread(&f);
auto t2 = new Thread(&g);
Thanks, I've got another problem:
void f()
{
sema.wait();
++x;
sema.notify();
}
sema is the global shared Semaphore (as above)
main.d(29): Error: function core.sync.semaphore.Semaphore.wait ()
is not callable using argument types () shared
main.d(29):
On Saturday, 14 July 2012 at 09:21:27 UTC, David Nadlinger wrote:
On Saturday, 14 July 2012 at 09:15:55 UTC, Minas Mina wrote:
Isn't this the way shared is used (or should be used)?
Should be used: probably yes. But functions/methods which are
able to act on shared data must be marke
Try -L-lX11
I have this code:
import std.stdio;
void main()
{
f();
g();
}
void f()
{
writeln("f()");
}
void g()
{
writeln("g()");
}
I compile with the command:
dmd test.d -profile
Then I execute it. It prints:
f()
g()
as expected. Shouldn't it print profiling informatio
Sorry, I just saw the generated file...
:p
I'm using condition variables to implement a monitor that
simulates the producer-consumer(unbounded buffer) scenario.
Note:
monitor is __gshared and is initialized in main(). Then the other
threads are created and run.
There is one producer thread, and 5 consumer threads.
void producer()
{
I think having the delete keyword for classes was a very good
thing, altough I don't know the problems it has for the GC and
probably other things.
Consider this scenario:
class Base
{
// ...
}
class Derived : Base
{
// ...
FILE *f;
this()
Thanks for the answers.
So clear() or destroy() in 2.060 be used to call the destructor,
but the actual memory of the object won't be freed, right?
Is this is true, why wasn't "delete" changed to behave like
destroy()?
I want to make a struct that defines a constructor:
struct Point
{
this()
{
}
}
However I get a compiler error:
"constructor main.Point.this default constructor for structs only
allowed with @disable and no body"
I wrote a @disable next to it but same error. I don't u
Thank you. Is it the way it is to have compatibility with C
structs?
On Sunday, 5 August 2012 at 16:42:16 UTC, Adam D. Ruppe wrote:
On Sunday, 5 August 2012 at 16:30:48 UTC, Minas Mina wrote:
Thank you. Is it the way it is to have compatibility with C
structs?
I'm not sure... I think so in part, but I think another part of
it is to make sure that s
I want to write a fibonacci(n) function that calculates the
result.
a) if n is known at compile time, use a template
b) if not, use a normal function
I know how to write a template version:
template fib(ulong n)
{
static if( n < 2 )
const fib = n;
else
Maybe you need a cast before malloc to convert it to a
"s_blockInfo*"?
Something like this:
template fib(ulong n)
{
static if( n < 2 )
const fib = n;
else
const fib = fib!(n-1) + fib!(n-2);
if( n < 2)
return n;
return fib(n-1) + fib(n-2);
}
It doesn't work of course, as I am in
On Monday, 6 August 2012 at 14:25:29 UTC, Eyyub wrote:
On Monday, 6 August 2012 at 13:46:14 UTC, Tobias Pankrath wrote:
You can check for compile time with
static if(__ctfe)
No, you can't.
__ctfe is a "CTFE-ed"(?) value.
But you can do something like that :
http://dpaste.dzfl.pl/e3f26239
On Monday, 6 August 2012 at 15:21:38 UTC, Philippe Sigaud wrote:
On Mon, Aug 6, 2012 at 3:54 PM, Minas Mina
wrote:
Something like this:
template fib(ulong n)
{
static if( n < 2 )
const fib = n;
else
const fib = fib!(n-1) + fib!(
On Monday, 6 August 2012 at 15:21:38 UTC, Philippe Sigaud wrote:
On Mon, Aug 6, 2012 at 3:54 PM, Minas Mina
wrote:
Something like this:
template fib(ulong n)
{
static if( n < 2 )
const fib = n;
else
const fib = fib!(n-1) + fib!(
On Monday, 6 August 2012 at 15:56:52 UTC, Namespace wrote:
Take a look into std.math:
https://github.com/D-Programming-Language/phobos/blob/master/std/math.d
I found this:
real sin(real x) @safe pure nothrow; /* intrinsic */
And these:
creal sin(creal z) @safe pure nothrow
{
creal cs =
On Monday, 13 August 2012 at 22:06:08 UTC, Namespace wrote:
Can i link an assembler file .s with dmd like gcc with "gcc
out.s any.c -o out.exe"? If so, how?
.s, .c, .d files (source files), are not linked. What is linked,
are object files (.obj or .o).
GCC either compiles the .s file to an o
That's what I do:
import std.c.stdlib;
void main(string[] args)
{
if( args.length == 1 )
{
writeln("Some arguments, please!");
exit(-1);
}
}
On Sunday, 19 August 2012 at 23:48:01 UTC, Minas Mina wrote:
That's what I do:
import std.c.stdlib;
void main(string[] args)
{
if( args.length == 1 )
{
writeln("Some arguments, please!");
exit(-1);
}
}
Sorry, forgot to import std.stdio.
I have this struct:
struct S
{
int[] t;
@disable this();
this(int sz)
{
t = new int[sz];
t[] = 1;
}
S opCall(int sz)
{
S s = S(sz);
return s;
Is there n article that explains the different types of Ranges?
(InputRange, ForwardRange, etc) and their usage?
Why is it "if( __ctfe )" and not
static if.. ?
On Wednesday, 12 December 2012 at 14:28:48 UTC, Zardoz wrote:
How I can compile with static linking with dmd ?
I try with dmd -L-static
but i get this error :
/usr/bin/ld: cannot find -lgcc_s
I used before gdc with -static options and owrked well on it,
but I need to use now dmd.
Try usi
On Sunday, 23 December 2012 at 12:08:47 UTC, Namespace wrote:
As long as you use structs this should work, as you can see
here: http://dpaste.dzfl.pl/03adf3d1
But if you use classes, it does not work anymore. So I like it
a lot, that it works with structs. :)
Thank you. I had forgotten to supp
On Sunday, 23 December 2012 at 20:40:09 UTC, Namespace wrote:
Minas Mina:
Show me the whole code, I think that your opBinary functions
returns rvalues.
This would be a good and important case for "auto ref". But
until now it is only for template paramters...
struct Vector3
{
On Sunday, 23 December 2012 at 23:59:55 UTC, Jonathan M Davis
wrote:
On Monday, December 24, 2012 00:48:01 Namespace wrote:
but Andrei is dead set against
- Jonathan M Davis
Why?
On Friday, 28 December 2012 at 12:47:03 UTC, Namespace wrote:
On Friday, 28 December 2012 at 12:28:01 UTC, bearophile wrote:
Namespace:
How likely is it that "auto ref" will implemented in this
release?
Walter wants to release 2.061 "soon". So maybe that's for the
successive (unstable?) ver
So when it will be fixed I will be able to write:
void foo(auto ref Vector3 v);
and it will pass copies or references depending on the situation?
On Wednesday, 16 January 2013 at 14:15:46 UTC, n00b wrote:
Nevermind, found it myself.
SysTime* sys = new SysTime(standardTime, UTC());
sys.hour;
Le 16/01/2013 08:07, n00b a écrit :
Hello, I'm kinda ashamed to ask that here, but std.datetime
documentation is so complex... I only want to get h
I am trying to create a BVH tree structure to speed up
raytracing. So far it has been fine. I have created the BVH tree.
It works for 202 triangles/spheres.
However, when the scene has more spheres/triangles, I get a
segmentation fault when the rays are traces, not when the tree is
being buil
On Thursday, 24 January 2013 at 13:22:20 UTC, Maxim Fomin wrote:
On Thursday, 24 January 2013 at 10:14:29 UTC, Minas Mina wrote:
I am trying to create a BVH tree structure to speed up
raytracing. So far it has been fine. I have created the BVH
tree. It works for 202 triangles/spheres
I found what the root of all evil was - The GC.
After disabling it, the program runs fine.
Maybe. I am re-writing the code in C++ to see, and also to
compare the performance.
On Friday, 25 January 2013 at 16:19:15 UTC, Maxim Fomin wrote:
On Friday, 25 January 2013 at 15:15:32 UTC, Minas Mina wrote:
I found what the root of all evil was - The GC.
After disabling it, the program runs fine.
Perhaps you was working with C code, GC + legacy code sometimes
lead to
Why is "const ref" not a good choice?
auto in?
in ref?
How can I define operator += for a struct?
On Monday, 8 April 2013 at 12:37:34 UTC, Simen Kjaeraas wrote:
On 2013-04-08, 14:23, Minas Mina wrote:
How can I define operator += for a struct?
http://dlang.org/operatoroverloading.html
In short:
struct S {
auto opOpAssign( string op : "+" )( S other ) {
// Do
On Saturday, 20 April 2013 at 15:49:47 UTC, Dementor561 wrote:
I have all the needed files to use Direlect3, and I have Mono-D
installed on Xamarin, I was wondering how I could put it all
together in a project.
1) Do you use windows or linux?
2) Have you built derelict3?
3) If you are using li
If you aren't comfortable with either C++ or D I would suggest to
do the tutorials with C++, as there are no OpenGL tutorials for
D. Don't try to learn two things at the same time.
On Saturday, 27 April 2013 at 18:14:11 UTC, Michael wrote:
According to http://dlang.org/const3.html
The simplest immutable declarations use it as a storage class.
It can be used to declare manifest constants.
So, immutable string s = "..."; should be a manifest constant.
If it is a constant
On Tuesday, 7 May 2013 at 23:09:29 UTC, Matic Kukovec wrote:
Hi
I'm running Windows Vista 64 with dmd 2.062.
I have a simple program:
import std.stdio, core.memory, std.cstream;
void main()
{
string[] temp_array;
for(int i=0;i<500;i++)
{
++temp_arra
On Thursday, 30 May 2013 at 16:48:33 UTC, bearophile wrote:
Shriramana Sharma:
Hello. I have always loved the readability of C++'s
and/or/not/xor
word-like logical operators but It doesn't seem to be
available in D.
and/or/not are less visually noisy, they look better than the
ugly &&/||/!
On Wednesday, 23 December 2015 at 22:29:31 UTC, Andrew Chapman
wrote:
On Wednesday, 23 December 2015 at 11:46:37 UTC, Jakob Ovrum
wrote:
On Wednesday, 23 December 2015 at 11:21:32 UTC, Jakob Ovrum
wrote:
Dynamic memory allocation is expensive. If the string is
short-lived, allocate it on the st
On Wednesday, 14 March 2012 at 05:44:24 UTC, Chris Pons wrote:
I'm new, and trying to incorporate assert and enforce into my
program properly.
My question revolves around, the fact that assert is only
evaluated when using the debug switch. I read that assert
throws a more serious exception th
On Sunday, 7 February 2016 at 19:43:23 UTC, rsw0x wrote:
On Sunday, 7 February 2016 at 19:39:27 UTC, rsw0x wrote:
On Sunday, 7 February 2016 at 19:27:19 UTC, Charles Hixson
wrote:
If I define a shared ulong variable, is increment an atomic
operation?
E.g.
shared ulong t;
...
t++;
It seems
I'm trying to inherit from Logger, and I my custom logger to
print to stdout using writeln(). But I can't because writeLogMsg
is @safe, whereas writeln() is @system.
Why is writeLogMsg @safe? This is too restrictive.
On Monday, 22 February 2016 at 23:03:38 UTC, Jonathan M Davis
wrote:
On Monday, February 22, 2016 22:22:01 Minas Mina via
Digitalmars-d-learn wrote:
[...]
Short answer:
[...]
Great, thanks.
Hello.
I'm trying to install DCD on windows 8.1 using DUB but I get an
error.
When executing "dub build --build=release --config=client" I get
the following error:
=> Root package dcd contains reference to invalid package
libdparse >=0.5.0 <0.6.0 <=
On Friday, 4 March 2016 at 13:53:22 UTC, aki wrote:
Is it okay to modify associative array while iterating it?
import std.stdio;
void main() {
string[string] hash = [ "k1":"v1", "k2":"v2" ];
auto r = hash.byKeyValue();
while(!r.empty) {
auto key = r.front
I added a WinMain function to my application because I don't want
it to open a console when running on windows.
But now it doesn't even start...
extern (Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
bool b = true;
while
On Saturday, 5 March 2016 at 14:08:28 UTC, Mike Parker wrote:
On Saturday, 5 March 2016 at 14:01:11 UTC, Mike Parker wrote:
If you use WinMain, you do not need that flag.
Actually, I need to amend that. It isn't needed with WinMain
when using the Microsoft linker, but it is when using OPTLIN
Hello, I have followed the instructions here
(http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to
install DMD, druntime and phobos from source.
My platform is Ubuntu 15.10 x64.
This is the error I get:
http://pastebin.com/kWCv0ymn
On Wednesday, 9 March 2016 at 16:13:38 UTC, Minas Mina wrote:
Hello, I have followed the instructions here
(http://wiki.dlang.org/Starting_as_a_Contributor#POSIX) to
install DMD, druntime and phobos from source.
My platform is Ubuntu 15.10 x64.
This is the error I get:
http://pastebin.com
On Tuesday, 21 October 2014 at 08:02:52 UTC, bearophile wrote:
Currently this code gets rejected:
const int[] a = [1];
void main() pure {
auto y = a[0];
}
test2.d(3,14): Error: pure function 'D main' cannot access
mutable static data 'a'
test2.d(3,14): Error: pure function 'D main' cannot
I intent to use D to make a small 2D game.
I have downloaded eclipse, DDT plugin and dub. I also set the
path to dub in eclipse.
So I made a new project, tested a writeln and it worked. The next
step was to add some dependencies for derelict. I need SFML for
now (and DerelictUtils of course).
Oh and another thing: The program compiles right now but I can't
execute it because for some reason:
Failed to create a child process.
Cannot run program
"/home/minas/Projects/eclipse_workspace/DTest/dtest" (in
directory "/home/minas/Projects/eclipse_workspace/DTest"):
error=13, Permission den
I have written a script that visits all directories in the
current directory and executes a command. In my case, "git pull".
When running the script serially, everything is fine. All git
repositories are pulled.
But I'd like to pull multiple repositories in parallel to speed
things up.
So I
bump
74 matches
Mail list logo