September 02

On Friday, 1 September 2023 at 13:45:05 UTC, evilrat wrote:

>

It is shadowing default implicit "import object;", here a demonstration

// this example shows default implicit import of "object" module
// compile this example:
//   ldc2 -c test.d
// output:
//   tuple("object", "core", "main", "thisModule")

// just a random import
import core.stdc.stdio;

void main() { }

alias thisModule = __traits(parent, main);
pragma(msg,  __traits(allMembers, thisModule)); // has implicitly imported 'object' module

Is there no way for the two to coexist?

September 02

On Saturday, 2 September 2023 at 03:18:31 UTC, confused wrote:

>

On Friday, 1 September 2023 at 13:31:37 UTC, bachmeier wrote:

>

You can read the documentation for object.d here. It's kind of important.

I'm not sure which specific part of the documentation was supposed to illuminate the exact nature of that error.

This was your inquiry:

>

I have in fact defined a module called object. How is that related to this error?

And at the very top of the page it says:

>

Forms the symbols available to all D programs. Includes Object, which is the root of the class object hierarchy. This module is implicitly imported.

That means there's a conflict with your module. This hasn't ever been an issue for me, so I can't tell you precisely why it gives that specific error message, but it explains how it's related, per your inquiry.

The easy fix is to not name your module something other than object.

September 02

On Saturday, 2 September 2023 at 03:27:51 UTC, confused wrote:

>

So I guess my next question is why, exactly, classes can, in fact, be implemented in betterC, but are not?

IIRC you can have extern(C++) classes in betterC, the real issue is the plain extern(D) classes which has some assumptions that are not present in betterC runtime.
Be careful though as extern(C++) classes have a bit different behavior where you might not expect it.
Specifically they have different vtable layout and some quirks with regard to multiple inheritance which is not available in D.
They might have some different destructor logic, and maybe there is more...

Otherwise you will have to mimic "classes" behavior with some template magic, just like OOP in C similar to COM model or gtk gobject, this means no fancy keyword and no language support for them though. But with all the templates and CTFE this shouldn't be a problem.

Also if you have read this forums regarding betterC... well, I think its only valid real use cases are tiny microcontrollers and WebAsm (because of GC), but the latter case can probably avoided with custom D runtime and people in fact has crafted some custom implementations.

September 02
On Saturday, September 2, 2023 4:38:41 AM BST confused via Digitalmars-d-learn wrote:
> On Friday, 1 September 2023 at 13:45:05 UTC, evilrat wrote:
> > It is shadowing default implicit "import object;", here a demonstration
> >
> > ```d
> > // this example shows default implicit import of "object" module
> > // compile this example:
> > //   ldc2 -c test.d
> > // output:
> > //   tuple("object", "core", "main", "thisModule")
> >
> > // just a random import
> > import core.stdc.stdio;
> >
> > void main() { }
> >
> > alias thisModule = __traits(parent, main);
> > pragma(msg,  __traits(allMembers, thisModule)); // has
> > implicitly imported 'object' module
> > ```
>
> Is there no way for the two to coexist?

If you put it into a package, then you could have your own object module that then isn't at the top level - e.g. mypkg/object.d with

module mypkg.object;

but you can't have more than one module in your program with the same full module name. So, in the case of the top-level module, object, you can only declare your own if you replace the default one, which you might do in some special situations, but it's not something that you would normally do, and you can never have both the normal object module and your own in the same program.

- Jonathan M Davis



September 04
On Saturday, 2 September 2023 at 07:59:31 UTC, Jonathan M Davis wrote:
> If you put it into a package, then you could have your own object module that then isn't at the top level - e.g. mypkg/object.d with
>
> module mypkg.object;
>
> but you can't have more than one module in your program with the same full module name. So, in the case of the top-level module, object, you can only declare your own if you replace the default one, which you might do in some special situations, but it's not something that you would normally do, and you can never have both the normal object module and your own in the same program.
>
> - Jonathan M Davis

So then I guess I'd still like to know how I'm expected to store and access an array of characters without the C runtime as I tried in my original post.
September 04
On Monday, 4 September 2023 at 07:39:21 UTC, confused wrote:
>
> So then I guess I'd still like to know how I'm expected to store and access an array of characters without the C runtime as I tried in my original post.

Without C runtime functions such as malloc you can still have fixed-length arrays, for string variables the compiler will emit null-terminated string at compile time in cases like that making it compatible with C functions.

Note that it not the case for other string operations like concat operator (is it available in betterC?), in that case if you want to pass the resulting string you have to add null terminator by hand.

If you need to allocate memory at runtime and still wan't to avoid C runtime, well I guess you have to do some syscalls then...
Or use another allocator library, jmalloc maybe? Though I don't have the experience with them and don't know if they are using C runtime somewhere inside or handle that low level OS/syscalls stuff by itself.
September 08

On Monday, 4 September 2023 at 07:39:21 UTC, confused wrote:

>

So then I guess I'd still like to know how I'm expected to store and access an array of characters without the C runtime as I tried in my original post.

You are going to allocate memory using the system call of your operation system and then you'll use a pointer as you would if you had used "malloc".

Is this what you are trying to do?

1 2
Next ›   Last »