emplace, immutable members and undefined behaviour

2015-11-15 Thread aewils via Digitalmars-d-learn
According to http://dlang.org/const3.html any modification of immutable data causes undefined behaviour. Now I want to initialise a struct with immutable members in some malloc'd memory and found the emplace function. I came up with the following code: import core.stdc.stdlib; import

Re: What does the -betterC switch in dmd do?

2015-11-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-11-12 23:24, Justin Whear wrote: I believe the purpose of the switch is to help folks who are trying to write for bare or embedded systems by not emitting references to the D runtime library and runtime module information. Whether it actually does that in its current implementation is

Re: emplace, immutable members and undefined behaviour

2015-11-15 Thread Tobias Pankrath via Digitalmars-d-learn
this compiles and runs fine. Because emplace expects a typed pointer, it actually modifies (*p).x and (*p).y As far as I understand, this causes undefined behavior. Are there any (safe) alternatives to this code other than making the immutable members mutable? As long as there are no other

Re: emplace, immutable members and undefined behaviour

2015-11-15 Thread aewils via Digitalmars-d-learn
On Sunday, 15 November 2015 at 11:12:02 UTC, Tobias Pankrath wrote: On Sunday, 15 November 2015 at 10:59:43 UTC, Tobias Pankrath wrote: Point* p = (allocate memory from somewhere); emplace!Point(p, 1, 2); immutable(Point)* immutableP = cast(immutable(Point)*) p; You could also use the

Re: emplace, immutable members and undefined behaviour

2015-11-15 Thread Tobias Pankrath via Digitalmars-d-learn
On Sunday, 15 November 2015 at 10:59:43 UTC, Tobias Pankrath wrote: Point* p = (allocate memory from somewhere); emplace!Point(p, 1, 2); immutable(Point)* immutableP = cast(immutable(Point)*) p; You could also use the emplace version that takes untyped memory:

My is the order of parameters reversed for functions that are dynamically loaded from shared C libraries?

2015-11-15 Thread David Nies via Digitalmars-d-learn
Apparantly, the order in which parameters are passed to a dynamically loaded C function is reversed. See the following minimal example: %> cat dll.c #include "stdio.h" int dll2(const char* first, const char* second) { printf("dll2() - first: '%s', second: '%s'\n", first,

Re: My is the order of parameters reversed for functions that are dynamically loaded from shared C libraries?

2015-11-15 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 15 November 2015 at 18:02:01 UTC, David Nies wrote: On Sunday, 15 November 2015 at 18:00:09 UTC, David Nadlinger wrote: On Sunday, 15 November 2015 at 17:54:27 UTC, David Nies wrote: How can I make sure the order is correct? Whenever you use a C function, it must be marked as,

Re: What does the -betterC switch in dmd do?

2015-11-15 Thread Meta via Digitalmars-d-learn
On Sunday, 15 November 2015 at 15:34:19 UTC, Jacob Carlborg wrote: I'm pretty sure that the only things that are excluded are module info and type info. It's still possible to use "new" and all the array features that requires support in the runtime (slicing, concatenation, appending and so

Re: on structs by reference

2015-11-15 Thread Ali Çehreli via Digitalmars-d-learn
On 11/14/2015 07:53 AM, Alex wrote: > 3. The only point I stumble on is, that the main feature in my program > is, that the underlying array, to which my slices refer to never > changes. So, I'm going to have more and more slices, which are going to > be smaller and smaller and each points to

Any D IDE on Mac OSX with debugging support?

2015-11-15 Thread Vadim Lopatin via Digitalmars-d-learn
Hello, Is there any IDE which allows debugging D apps on OSX? I'm trying Mono-D, but getting error "Debugger operation failed A syntax error in expression, near 'sizeof(void*)'" GDB is installed using homebrew. Probably, something is wrong with my gdb. When I'm trying to start debugging

Re: Any D IDE on Mac OSX with debugging support?

2015-11-15 Thread Rikki Cattermole via Digitalmars-d-learn
On 16/11/15 7:45 PM, Vadim Lopatin wrote: Hello, Is there any IDE which allows debugging D apps on OSX? I'm trying Mono-D, but getting error "Debugger operation failed A syntax error in expression, near 'sizeof(void*)'" GDB is installed using homebrew. Probably, something is wrong with my

Re: My is the order of parameters reversed for functions that are dynamically loaded from shared C libraries?

2015-11-15 Thread David Nies via Digitalmars-d-learn
On Sunday, 15 November 2015 at 18:00:09 UTC, David Nadlinger wrote: On Sunday, 15 November 2015 at 17:54:27 UTC, David Nies wrote: How can I make sure the order is correct? Whenever you use a C function, it must be marked as, even if it's through a function pointer as in this case. Just

Re: My is the order of parameters reversed for functions that are dynamically loaded from shared C libraries?

2015-11-15 Thread David Nadlinger via Digitalmars-d-learn
On Sunday, 15 November 2015 at 17:54:27 UTC, David Nies wrote: How can I make sure the order is correct? Whenever you use a C function, it must be marked as, even if it's through a function pointer as in this case. Just apply the attribute to the dll2_fn and dll3_fn declarations. Hope this

Re: My is the order of parameters reversed for functions that are dynamically loaded from shared C libraries?

2015-11-15 Thread David Nies via Digitalmars-d-learn
On Sunday, 15 November 2015 at 18:12:52 UTC, David Nadlinger wrote: On Sunday, 15 November 2015 at 18:02:01 UTC, David Nies wrote: How do I mark it as such? Can you please give an example? Thanks for the quick reply! :) Just add extern(C) to the beginning of the "alias" line. — David

Re: My is the order of parameters reversed for functions that are dynamically loaded from shared C libraries?

2015-11-15 Thread David Nadlinger via Digitalmars-d-learn
On Sunday, 15 November 2015 at 18:02:01 UTC, David Nies wrote: How do I mark it as such? Can you please give an example? Thanks for the quick reply! :) Just add extern(C) to the beginning of the "alias" line. — David