Re: Static indexing

2022-01-12 Thread Ali Cehreli via Digitalmars-d-learn
On 1/12/22 00:59, JG wrote: > I want to make a type which has two fields x and y but can > also be indexed with [0] and [1] checked at compile time. std.typecons.Tuple already does that. You can add "member functions" like foo() below by taking advantage of UFCS: import std.typecons; alias P

Re: TLS definition in curses.o section .tbss mismatches non-TLS reference

2009-12-14 Thread Ali Cehreli
Gareth Charnock Wrote: > And now I see there was an article about that on website all > along. And that article is here: http://www.digitalmars.com/d/2.0/migrate-to-shared.html Ali

Re: struct members not default initialized?

2009-12-07 Thread Ali Cehreli
bearophile Wrote: > This prints 42 0.00 with the latest dmd2 and 42 nan with an older dmd1. > It can be a bug: It prints garbage here with 2.037. :/ As I've responded to my own post :), I think the initialization is meant only for static objects. > > import std.c.stdio: printf; > > stru

Re: struct members not default initialized?

2009-12-07 Thread Ali Cehreli
Ali Cehreli Wrote: > (I must be missing something here Yes I am! :) > I've been under the impression that struct members would always be > initialized. Having seen D an init-happy language compared to C and C++, > that's what I would have expected. :) I still think

struct members not default initialized?

2009-12-07 Thread Ali Cehreli
(I must be missing something here; this is such a fundamental operation and I can't find a bug report on it.) I've been under the impression that struct members would always be initialized. Having seen D an init-happy language compared to C and C++, that's what I would have expected. :) Should

Re: Question about mutable arrays

2009-11-19 Thread Ali Cehreli
A Bothe Wrote: > I've found a problem that occurred since DMD 2.034: I am testing it with 2.036. > When I've created a dynamic array like > string[] a; I like to see it a "slice." Even if we go with "dynamic array," I see it as an empty dynamic array. > and I want to assign something via the

Re: cast(int) getting an unexpected number

2009-11-04 Thread Ali Cehreli
Ok, I messed up my previous comment while moving rmcguire's lines around. Trying again... Also, I am not sure about the last bit now. :) rmcguire Wrote: > why is this not a compiler bug? > because: > import std.stdio; > > void main() { > float f=0.01; Just an information: 0.01 is doubl

Re: cast(int) getting an unexpected number

2009-11-04 Thread Ali Cehreli
rmcguire Wrote: > why is this not a compiler bug? > because: > import std.stdio; > > void main() { > float f=0.01; > results in: > 0.01->0 0.01 is double, there is type conversion there. > writefln("%0.2f->%d",f,cast(int)(f*100f)); > results in: > 0.01->1 f*100f is represente

Re: Scope const

2009-11-02 Thread Ali Cehreli
Jarrett Billingsley Wrote: > On Sat, Apr 11, 2009 at 5:33 AM, Kagamin wrote: > > If "in" is equivalent to "scope const". What "scope" means? Does it mean > > that this argument doesn't escape scope of this function? Then "const" > > parameters are not quite equivalent to "in" parameters. > > >

Reading till the end of standard input

2009-09-13 Thread Ali Cehreli
I am using dmd v2.032 and trying to read int values from the standard input: import std.cstream; void main() { while (!din.eof()) { int value; din.readf(&value); if (!din.eof()) { dout.writefln("read: ", value); } } } 1) If I - start the prog

Basic file i/o

2009-09-11 Thread Ali Cehreli
What is the simplest way of using a file? There are two 'File's in Phobos and they conflict: 1) struct File in std.stdio 2) class File in std.stream The one in std.stream.File is definitely what I want to use. What to do? Prefer using full names in D as in std.stream.File? Perhaps std.stdio is

Re: Is [ 0, 1, 2 ] an immutable array?

2009-08-12 Thread Ali Cehreli
Steven Schveighoffer Wrote: > > int[] a = [ 0, 1, 2 ]; > > a[0] = 42; > No, it's a mutable array. It's one of the quirks of D2 that bugs me. A > string literal is an immutable array but a normal array literal actually > allocates new space on the heap for the array every time you us

Re: 'static' keyword for positional array initialization

2009-08-12 Thread Ali Cehreli
Don Wrote: > > void main() > > { > > int[2] static_0 = [ 1, 1 ]; > > int[2] static_1 = [ 1:1 ]; > > } > > > > dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): > > Assertion `j < edim' failed. > > I've added this to Bugzilla as bug 3246. With a patch . Thank you fo

Re: 'static' keyword for positional array initialization

2009-08-12 Thread Ali Cehreli
Lars T. Kyllingstad Wrote: > I've tried with DMD 2.031, and I can't reproduce this. This works fine > for me: > >int[2] static_0 = [ 1, 1 ]: >int[2] static_1 = [ 1:1 ]; > > Where did you put the declarations? I've tried putting them at both > module level and in a class, and both times

Is [ 0, 1, 2 ] an immutable array?

2009-08-11 Thread Ali Cehreli
Does the expression [ 0, 1, 2 ] form an immutable array? If so, is the assignment to a[0] undefined below? Is it trying to modify an immutable element? int[] a = [ 0, 1, 2 ]; a[0] = 42; The reason for my thinking that [ 0, 1, 2] is an array is because it has the .dup property and this w

'static' keyword for positional array initialization

2009-08-11 Thread Ali Cehreli
The 'static' keyword is required by dmd 2.031 for the second of these two definitions: int[2] static_0 = [ 1, 1 ]; static int[2] static_1 = [ 1:1 ]; Is this inconsistency by design? Should 'static' be required for both or neither? Ali

Reading bool as the string "true" or "false"

2009-07-29 Thread Ali Cehreli
I am trying to learn to read bool as a string and have it converted to bool. Too much to ask? :) This is what I know in C++: #include #include using namespace std; int main() { cin >> boolalpha; cout << boolalpha; bool b = false; cin >> b; cout << b << endl; } cin and c