I don't understand betterC

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Sep 2 07:59:31 UTC 2023


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





More information about the Digitalmars-d-learn mailing list