unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
[code] void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { } struct vec(size_t N, T, string AS) { T[N] data; } void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); } [/code] compile with new dmd v2.066.0 and get error: Error: template opbin.doSome(ulong N, T, string AS)(vec!(N, T, AS) v)

Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
On Monday, 25 August 2014 at 11:41:28 UTC, bearophile wrote: Oleg B: [code] void doSome(size_t N, T, string AS)( vec!(N,T,AS) v ) { } struct vec(size_t N, T, string AS) { T[N] data; } void main() { doSome( vec!(3,float,xyz)([1,2,3]) ); } [/code] compile with new dmd v2.066.0 and get error:

Re: unclear compile error for struct with string template

2014-08-25 Thread Oleg B via Digitalmars-d-learn
and when I minimal fix my libs with this issue compiler fails without any output... =( % gdb dmd (gdb) run -unittest matrix.d vector.d Starting program: /usr/bin/dmd -unittest matrix.d vector.d [Thread debugging using libthread_db enabled] Using host libthread_db library

Re: using D without GC

2015-06-08 Thread Oleg B via Digitalmars-d-learn
On Monday, 8 June 2015 at 13:37:40 UTC, Marc Schütz wrote: On Monday, 8 June 2015 at 12:24:56 UTC, Oleg B wrote: I guess you should follow andrei's post about new allocators! Can you get link to this post? These are some of his posts:

rt_finalize question

2015-06-09 Thread Oleg B via Digitalmars-d-learn
Hello. In object.di rt_finalize calls for class objects in destroy func. I not found it in dmd source on github and not found in druntime sources. I think rt_finalize must call dtors for object and base classes, but I think that's not all. Or if it all has it code logic problems? void

Re: rt_finalize question

2015-06-09 Thread Oleg B via Digitalmars-d-learn
I found it https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1350 Creates new questions. Why it's extern(C)? What must do collectHandler function? If I understand correctly monitor relates to multithreading control (Mutex?).

const and mutable opApply's

2016-06-19 Thread Oleg B via Digitalmars-d-learn
Hello struct WTable { ... private enum opApply_body = q{ if( smt ) { foreach( f; 0 .. size-1 ) foreach( t; f+1 .. size ) if( auto r = dlg(f,t,data[getIndex(f,t)]) ) return r; } else {

new XML and JSON libs and replacement of std.net.curl

2016-08-15 Thread Oleg B via Digitalmars-d-learn
Hello. In std.xml docs I read that is deprecated, and std.net.curl can be deprecated too (not remember here I read about std.net.curl). About std.json I read what it's has slow (de)serialization. What I must use at this time? vibe.data.json has evolution

Cross-compile with LDC

2017-02-08 Thread Oleg B via Digitalmars-d-learn
Hello all! I want to build ldc cross compiller. I found this instruction https://wiki.dlang.org/LDC_cross-compilation_for_ARM_GNU/Linux, but I have some doubts: will it works with ldc-1.1.0? Particularly interested in the patch

Re: Cross-compile with LDC

2017-02-08 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 8 February 2017 at 16:21:49 UTC, kinke wrote: On Wednesday, 8 February 2017 at 14:57:41 UTC, Oleg B wrote: Hello all! I want to build ldc cross compiller. I found this instruction https://wiki.dlang.org/LDC_cross-compilation_for_ARM_GNU/Linux, but I have some doubts: will it

Package visibility strange behaviour

2017-02-27 Thread Oleg B via Digitalmars-d-learn
Hello. Is this behavior normal, or it's a bug? And if it's normal why it's normal? I want to use function with `package` visibility in same package where it's defined, but I don't. ```d module package_visible; package void foo() { } void main() { foo(); } ``` ``` % rdmd package_visible.d

getSymbolsByUDA toSymbols error instantiating

2017-02-27 Thread Oleg B via Digitalmars-d-learn
Hello. I have this code: ```d import std.traits; enum myuda; class A { @myuda int x; } class B : A { @myuda int some; void foo() { foreach (s; getSymbolsByUDA!(typeof(this), myuda)) {} } } void main() { (new B).foo(); } ``` And have this error: ``` % rdmd uda_symbols.d

Re: How to get the name for a Tid

2017-02-27 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 23 November 2016 at 21:04:38 UTC, Christian Köstlin wrote: std.concurrency contains the register function to associate a name with a Tid. This is stored internally in an associative array namesByTid. I see no accessors for this. Is there a way to get to the associated names of a

Enums and immutables

2017-03-18 Thread Oleg B via Digitalmars-d-learn
Hello. I found strange behavior while casting enum array and immutable array. import std.stdio; void main() { enum arr = cast(ubyte[])[0,0,0,1,0,0,0,2,0,0,0,3,0,0,0,4]; auto arr1 = cast(void[])arr; immutable arr2 = cast(immutable(void)[])arr; enum arr3 = cast(void[])arr;

Re: Automatic function body writing howto?

2017-08-17 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 16 August 2017 at 22:48:59 UTC, Meta wrote: It's hard to tell offhand but I would recommend that you extract the inner string into a function that generates that string, allowing you to print out the finished product before mixing it in. It's have a same result...

Automatic function body writing howto?

2017-08-16 Thread Oleg B via Digitalmars-d-learn
I want declare only signature of function and build body code by CTFE. module mdl; import std.stdio; import std.traits; import std.string; enum autofnc; @autofnc { int foo(int); int bar(int); } void main() { writeln(foo(12)); } mixin cfuncR; mixin template cfuncR()

Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn
and this is unexpected for me too immutable ushort y = 0; foo(y); // byte

ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn
Hello. I have this code import std.stdio; void foo(byte a) { writeln(typeof(a).stringof); } void foo(short a) { writeln(typeof(a).stringof); } void foo(int a) { writeln(typeof(a).stringof); } void main() { foo(0); // int, and byte if not define foo(int) foo(ushort(0)); // byte

Re: ushort calls byte overload

2017-05-30 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 21:42:03 UTC, Daniel Kozak wrote: Compiler do many assumptions (it is sometimes useful). but if compiler find one-to-one correspondence it don't make assumptions, like here? import std.stdio; void f(ushort u) { writeln("ushort"); } void f(ubyte u) {

non-block reading from pipe stdout

2017-10-02 Thread Oleg B via Digitalmars-d-learn
Hello. I run program through std.process.pipeShell and want to read from it stdout in loop. How do this non-blocking? I try int fd = p.stdout.fileno; int flags = fcntl(fd, F_GETFL, 0); flags |= O_NONBLOCK; fcntl(fd, F_SETFL, flags); but get error "Resource

Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 12:32:43 UTC, kdevel wrote: IMHO a program should sleep (consume 0 CPU time and 0 energy) if there is nothing to process. This is best accomplished by not polling on a file descriptor in order to check if data has arrived. If your program must yield() there's

betterC and struct destructors

2017-09-11 Thread Oleg B via Digitalmars-d-learn
Hello. I try using destructor in betterC code and it's work if outer function doesn't return value (void). Code in `scope (exit)` works as same (if func is void all is ok). In documentation I found https://dlang.org/spec/betterc.html#consequences 12 paragraph: Struct deconstructors. Why

Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote: On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote: but get error "Resource temporarily unavailable". You get EAGAIN because there is no data available at the time of reading. From the manpage of read: ERRORS EAGAIN

Re: non-block reading from pipe stdout

2017-10-03 Thread Oleg B via Digitalmars-d-learn
On Tuesday, 3 October 2017 at 10:45:21 UTC, kdevel wrote: On Tuesday, 3 October 2017 at 00:22:28 UTC, Oleg B wrote: but get error "Resource temporarily unavailable". You get EAGAIN because there is no data available at the time of reading. From the manpage of read: ERRORS EAGAIN

betterC and noboundscheck

2017-11-22 Thread Oleg B via Digitalmars-d-learn
Hello. I try compile simple example: import core.stdc.stdio; import std.algorithm : min; extern (C) void main() { char[256] buf; buf[] = '\0'; auto str = "hello world"; auto ln = min(buf.length, str.length); buf[0..ln] = str[0..ln]; printf("%s\n", buf.ptr); } rdmd

call Pascal DLL functions from D

2017-10-24 Thread Oleg B via Digitalmars-d-learn
Hello. I have DLL written on Pascal and "headers" for use it (types and functions signatures definitions). How I can port "headers" to D? Calling convention is `stdcall` (`extern (Windows)` for D), arguments of some functions is structs of structs and etc with static array fields:

Re: call Pascal DLL functions from D

2017-10-25 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 04:30:12 UTC, Basile B. wrote: On Wednesday, 25 October 2017 at 03:12:56 UTC, Oleg B wrote: 2. `array[A..B] of TFoo` is `TFoo[B-A+1]` (static array) No A-B. In Pascal the upper bound of a range (like here but i'm not sure this i called like that in the

Re: call Pascal DLL functions from D

2017-10-25 Thread Oleg B via Digitalmars-d-learn
On Wednesday, 25 October 2017 at 03:36:54 UTC, Adam D. Ruppe wrote: I'd suggest just trying it and seeing if the functions return what you expect. Unfortunately they returns unexpected codes. Otherwise I wouldn't post question here. I go here then I have no idea to resolve problem.

Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn
Hello everyone! I try build this code with betterC import core.stdc.stdio; import std.format : format; extern(C) int main() { mixin(format!`enum str = "%s\0";`("hello")); fprintf(stderr, "%s\n", str.ptr); return 0; } but compilation fails

Re: Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn
On Thursday, 25 July 2019 at 12:20:04 UTC, Mike Franklin wrote: If you read the documentation for betterC (https://dlang.org/spec/betterc.html#consequences) you'll see that there are features of the D language which are not supported. Therefore, libraries that use such features (e.g.

Re: Is betterC affect to compile time?

2019-07-25 Thread Oleg B via Digitalmars-d-learn
On Thursday, 25 July 2019 at 12:34:15 UTC, rikki cattermole wrote: Those restrictions don't stop at runtime. It's vary sad. What reason for such restrictions? It's fundamental idea or temporary implementation?

must scope for delegates restrict compilation?

2019-10-03 Thread Oleg B via Digitalmars-d-learn
Hello all I think this code must get compilation error, but it didn't, furthermore result program get UB. https://run.dlang.io/is/Qpr278 Is this correct behavior and why?

How to define delegate what returns ref?

2020-08-28 Thread Oleg B via Digitalmars-d-learn
Hello all! syntax ref int delegate() foo0; or ref(int) delegate() foo1; or int delegate() ref foo2; are not valid. if I try alias alias refint = ref int; refint delegate() foo3; foo3 have type `int delegate()` (without `ref`) and it can't store delegate from object

Re: How to define delegate what returns ref?

2020-08-28 Thread Oleg B via Digitalmars-d-learn
On Friday, 28 August 2020 at 11:50:35 UTC, kinke wrote: On Friday, 28 August 2020 at 11:46:15 UTC, Oleg B wrote: How to do this more clearly? alias Dg = ref int delegate(); Dg foo; Thanks!

Re: Overload comparison operators for "nullable" types

2020-08-01 Thread Oleg B via Digitalmars-d-learn
On Thursday, 30 July 2020 at 14:52:17 UTC, H. S. Teoh wrote: On Thu, Jul 30, 2020 at 01:41:05PM +, Oleg B via Digitalmars-d-learn wrote: [...] Logically we can compare versions, but what must return `opCmp` if one of versions has 'not comparible' state? [...] opCmp is allowed to return

Overload comparison operators for "nullable" types

2020-07-30 Thread Oleg B via Digitalmars-d-learn
Hello! For example we can imagine struct Version. Version can be old or new and can be 'badly formed' or 'undefined' or other 'not comparible' ('uncompatible') state. Logically we can compare versions, but what must return `opCmp` if one of versions has 'not comparible' state? I think

Re: isPOD is broken?

2021-03-27 Thread Oleg B via Digitalmars-d-learn
On Friday, 26 March 2021 at 12:13:29 UTC, kinke wrote: A class *reference* is always a POD. Only structs can be non-PODs. In this case what means "does not have virtual functions, does not inherit"? Structs doesn't have virtual methods and they can't inherits.

isPOD is broken?

2021-03-26 Thread Oleg B via Digitalmars-d-learn
Hi all! class Foo { private int val; this(int v) { val = v; } int vv() { return val*2; } ~this() { } } class Bar : Foo { this(int v) { super(v); } override int vv() { return val*3; } } pragma(msg, __traits(isPOD, Foo)); pragma(msg, __traits(isPOD, Bar)); prints true

weird formattedRead

2021-04-09 Thread Oleg B via Digitalmars-d-learn
Hello, I have some doubts about working `formattedRead` with space chars. Example: ```d import std : formattedRead, DateTime, stderr, each; DateTime parseDT(string str) { int d,mo,y, h,m,s; formattedRead!"%d/%d/%d %d:%d:%d"(str, d,mo,y, h,m,s); return DateTime(y,mo,d, h,m,s); }