Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 27 August 2015 at 12:40:07 UTC, Mike James wrote: How about... A lot nicer. :)

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Mike James via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g

Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn
On Thursday, 27 August 2015 at 11:45:14 UTC, anonymous wrote: On Thursday 27 August 2015 13:15, BBasile wrote: https://github.com/BBasile/iz/blob/master/import/iz/types.d#L125 https://github.com/BBasile/iz/blob/master/import/iz/types.d#L150

Re: Casting pointers

2015-08-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/26/15 8:14 AM, John Burton wrote: This would be undefined behavior in c++ due to aliasing rules on pointers. It appears to work reliably in D when I try it, but that's obviously no guarantee that it's correct or will continue to do so. Is this correct code in D? And if not, what should I

Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn
On Thursday, 27 August 2015 at 12:56:26 UTC, anonymous wrote: On Thursday 27 August 2015 14:35, BBasile wrote: Anyway. I cheat a bit with attributes but as long as it's only for me...I know this kinds of functions are not phobos-level. Sure, as long as you're cautious and regard those

Re: Digger 2.3 verstr.h problem

2015-08-27 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-08-25 13:42:38 +, Vladimir Panteleev said: And, any idea how I can print getcwd() during compile time? I tried but it's not working by using the function directly... this is really strange. getcwd() doesn't work during compile time because it's a system call. I really don't

Re: order of declaration/definition

2015-08-27 Thread vitus via Digitalmars-d-learn
On Thursday, 27 August 2015 at 13:14:24 UTC, Daniel Kozák wrote: On Thu, 27 Aug 2015 13:01:02 + vitus via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: works ok for me V tom je ten problém :)

Re: Arrays of structs

2015-08-27 Thread anonymous via Digitalmars-d-learn
On Thursday 27 August 2015 14:35, BBasile wrote: Anyway. I cheat a bit with attributes but as long as it's only for me...I know this kinds of functions are not phobos-level. Sure, as long as you're cautious and regard those functions as unsafe, you may be fine. You still risk accidentally

Re: order of declaration/definition

2015-08-27 Thread vitus via Digitalmars-d-learn
On Monday, 24 August 2015 at 01:01:13 UTC, John Colvin wrote: enum A = 1; enum B = C; //Error static if(A) enum C = 0; enum D = C; //OK Is order supposed to matter here? Beter: enum E = 1; struct Foo{ enum X1 = E; static if(1) enum E = 2; enum X2 = E; } static

Re: order of declaration/definition

2015-08-27 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 27 Aug 2015 13:01:02 + vitus via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 24 August 2015 at 01:01:13 UTC, John Colvin wrote: enum A = 1; enum B = C; //Error static if(A) enum C = 0; enum D = C; //OK Is order supposed to matter here?

Re: order of declaration/definition

2015-08-27 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 27 Aug 2015 13:26:11 + vitus via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thursday, 27 August 2015 at 13:14:24 UTC, Daniel Kozák wrote: On Thu, 27 Aug 2015 13:01:02 + vitus via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote:

Re: What is this function call operator?

2015-08-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 27 August 2015 at 16:03:58 UTC, Gary Willoughby wrote: Sorry, I mean the three dots '...' that seems to be what the documentation is referring to. Also the `isCallable` template uses it. That just means it can take whatever arguments. The documentation is just saying it is

Re: What is this function call operator?

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 27 August 2015 at 16:12:35 UTC, Adam D. Ruppe wrote: On Thursday, 27 August 2015 at 16:03:58 UTC, Gary Willoughby wrote: Sorry, I mean the three dots '...' that seems to be what the documentation is referring to. Also the `isCallable` template uses it. That just means it can

Re: What is this function call operator?

2015-08-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 27 August 2015 at 15:18:24 UTC, Gary Willoughby wrote: What is this function call operator? (...) Where can i learn more about it? It is the () at the end of a thing. You can overload it in a struct by writing an opCall member.

Re: What is this function call operator?

2015-08-27 Thread anonymous via Digitalmars-d-learn
On Thursday 27 August 2015 17:18, Gary Willoughby wrote: What is this function call operator? (...) Where can i learn more about it? http://dlang.org/operatoroverloading.html#function-call http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opCall

Re: What is this function call operator?

2015-08-27 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 27 Aug 2015 15:18:22 + Gary Willoughby d...@nomad.so wrote: If you visit this link: http://dlang.org/phobos/std_traits.html#isCallable There is this paragraph: Detect whether T is a callable object, which can be called with the function call operator (...). What is

What is this function call operator?

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
If you visit this link: http://dlang.org/phobos/std_traits.html#isCallable There is this paragraph: Detect whether T is a callable object, which can be called with the function call operator (...). What is this function call operator? (...) Where can i learn more about it?

Re: What is this function call operator?

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 27 August 2015 at 15:19:15 UTC, Adam D. Ruppe wrote: On Thursday, 27 August 2015 at 15:18:24 UTC, Gary Willoughby wrote: What is this function call operator? (...) Where can i learn more about it? It is the () at the end of a thing. You can overload it in a struct by writing an

Error Compiling with -debug swtich

2015-08-27 Thread Jordan Wilson via Digitalmars-d-learn
Hello, Just wondering why compiling the following fails with the -debug switch, but appears to compile and execute fine without it: import std.stdio; import std.algorithm; import std.container; int main(string[] args) { Array!string letters = [b,a,c]; sort(letters[]); writeln

documentation for C/C++ interop

2015-08-27 Thread Laeeth Isharc via Digitalmars-d-learn
would someone care to work on updating this? I understand from Daniel's post in main list that the only thing that doesn't work is special member functions. that's different from what the documents say, and it is surely something important for D that people are aware of this. I don't

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Andrew Brown via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:26:55 UTC, rumbu wrote: On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio;

Arrays of structs

2015-08-27 Thread John Burton via Digitalmars-d-learn
I'm a c++ programmer trying to understand how memory allocation works in D. I created a struct and added a destructor to it. My understanding is that structs have deterministic destructors - they are called when the struct goes out of scope (unless it is allocated with new). Now if I put

Re: Arrays of structs

2015-08-27 Thread SimonN via Digitalmars-d-learn
Hi, On Thursday, 27 August 2015 at 10:05:31 UTC, John Burton wrote: understanding is that structs have deterministic destructors - they are called when the struct goes out of scope Yes, when they are declared right at the scope, and not contained in something that might live past the current

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Olivier Pisano via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:38:52 UTC, Andrew Brown wrote: That's lovely, thank you. One quick question, the length of the file is not a multiple of the length of ubyte, but the cast still seems to work. Do you know how it converts a truncated final section? Thanks again Andrew

Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn
On Thursday, 27 August 2015 at 10:05:31 UTC, John Burton wrote: I'm a c++ programmer trying to understand how memory allocation works in D. I created a struct and added a destructor to it. My understanding is that structs have deterministic destructors - they are called when the struct goes

Re: Arrays of structs

2015-08-27 Thread John Burton via Digitalmars-d-learn
Ok that's great thank you. It's quite hard trying to get a proper understanding of memory allocation in D after years of C++ / RAII / unique_ptr / shared_ptr . I understand the details of course but it's going to take a while to really know it. Is there any way to explicitly free a dynamic

Re: Arrays of structs

2015-08-27 Thread John Burton via Digitalmars-d-learn
Thanks again for the updates. I've experimented some more and believe I understand. To be honest I'm finding it very hard to find the right idioms in D for safe and efficient programming when I'm so used to C++ / RAII everywhere. I'll adapt though :P

Re: Arrays of structs

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote: Thanks again for the updates. I've experimented some more and believe I understand. To be honest I'm finding it very hard to find the right idioms in D for safe and efficient programming when I'm so used to C++ / RAII

Re: Arrays of structs

2015-08-27 Thread Olivier Pisano via Digitalmars-d-learn
On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote: To be honest I'm finding it very hard to find the right idioms in D for safe and efficient programming when I'm so used to C++ / RAII everywhere. I'll adapt though :P This is true for every new language you learn. You first

Re: Arrays of structs

2015-08-27 Thread BBasile via Digitalmars-d-learn
On Thursday, 27 August 2015 at 10:49:02 UTC, John Burton wrote: Thanks again for the updates. I've experimented some more and believe I understand. To be honest I'm finding it very hard to find the right idioms in D for safe and efficient programming when I'm so used to C++ / RAII

Re: multiline string literal with CRLF

2015-08-27 Thread Kagamin via Digitalmars-d-learn
Another option: Hello\r\n~ world;

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:38:52 UTC, Andrew Brown wrote: On Thursday, 27 August 2015 at 09:26:55 UTC, rumbu wrote: On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the

Re: Casting pointers

2015-08-27 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 26 August 2015 at 12:14:54 UTC, John Burton wrote: This would be undefined behavior in c++ due to aliasing rules on pointers. It appears to work reliably in D when I try it, but that's obviously no guarantee that it's correct or will continue to do so. Is this correct code in

Re: Arrays of structs

2015-08-27 Thread anonymous via Digitalmars-d-learn
On Thursday 27 August 2015 13:15, BBasile wrote: https://github.com/BBasile/iz/blob/master/import/iz/types.d#L125 https://github.com/BBasile/iz/blob/master/import/iz/types.d#L150 https://github.com/BBasile/iz/blob/master/import/iz/types.d#L191 Your use of @trusted is wrong and dangerous.

Re: Casting pointers

2015-08-27 Thread John Burton via Digitalmars-d-learn
Ok thank you. Seems to me that there is enough doubt that this is supported that I'd be best to avoid relying on it, or at least ensure that it's all encapsulated in something I can easily change.

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread Rikki Cattermole via Digitalmars-d-learn
On 27/08/15 9:00 PM, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g = cast(bool[])f;

Re: Reading and converting binary file 2 bits at a time

2015-08-27 Thread rumbu via Digitalmars-d-learn
On Thursday, 27 August 2015 at 09:00:02 UTC, Andrew Brown wrote: Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g

Re: linking-in libs under linux needed and not under windows

2015-08-27 Thread BBasile via Digitalmars-d-learn
On Thursday, 27 August 2015 at 04:57:14 UTC, Adam D. Ruppe wrote: On Thursday, 27 August 2015 at 02:50:58 UTC, BBasile wrote: So the Q: Is this difference normal ? Yes, it is a feature the Windows format supports but the Linux one doesn't. On Linux, you need to list the libraries on the

Reading and converting binary file 2 bits at a time

2015-08-27 Thread Andrew Brown via Digitalmars-d-learn
Hi, I need to read a binary file, and then process it two bits at a time. But I'm a little stuck on the first step. So far I have: import std.file; import std.stdio; void main(){ auto f = std.file.read(binaryfile); auto g = cast(bool[]) f; writeln(g); } but all the values of g then