Re: I don't understand betterC

2023-09-01 Thread bachmeier via Digitalmars-d-learn

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](https://dlang.org/phobos/object.html). 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.





Re: I don't understand betterC

2023-09-01 Thread confused via Digitalmars-d-learn

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?


Re: I don't understand betterC

2023-09-01 Thread confused via Digitalmars-d-learn

On Saturday, 2 September 2023 at 01:05:39 UTC, ryuukk_ wrote:
If you are looking for a better C you are not looking for 
classes


You contradict yourself

If you heard about betterC, then you heard about this: 
https://dlang.org/spec/betterc.html



Read it again, and specially this part: 
https://dlang.org/spec/betterc.html#consequences


C has no GC, therefore no class, see, your contradiction ;)


Actually, I'm not looking for C, I'm looking for *better* C. C 
with classes would, in fact, be better. Except I hate C++.


In any case, I read all those links already, but D documentation 
can be rather out of date sometimes, and after having found a 
blog online about retaining classes in ``` betterC ```, I decided 
to try it out. What that blog failed to mention was that such a 
simple means of retaining classes would conflict with ``` stdc 
```.


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


Re: I don't understand betterC

2023-09-01 Thread confused via Digitalmars-d-learn

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

You can read the documentation for object.d 
[here](https://dlang.org/phobos/object.html). 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.


Re: I don't understand betterC

2023-09-01 Thread ryuukk_ via Digitalmars-d-learn

On Friday, 1 September 2023 at 13:17:08 UTC, confused wrote:
On Friday, 1 September 2023 at 08:19:55 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
``size_t`` is defined in ``object.d`` which is implicitly 
imported into all modules.


If it cannot be found, one of three things is happening:

1) You have messed with some cli args related to picking 
druntime/phobos

2) You have defined a module called object.
3) You have a broken compiler install.


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


I'm interested in betterC as a curiosity, and trying to explore 
the extent to which D classes and object-oriented programming 
can be preserved within its bounds (because I really like 
classes, and I really like D, and I really hate C++, and I'm 
trying to learn about bare-metal programming).


Thank you, by the way, for sharing your knowledge and time.


If you are looking for a better C you are not looking for classes

You contradict yourself

If you heard about betterC, then you heard about this: 
https://dlang.org/spec/betterc.html



Read it again, and specially this part: 
https://dlang.org/spec/betterc.html#consequences


C has no GC, therefore no class, see, your contradiction ;)


Re: Keeping data from memory mapped files

2023-09-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Sep 01, 2023 at 03:53:42AM +, Alexibu via Digitalmars-d-learn wrote:
> Why do I need to copy data out of memory mapped files to avoid seg faults.
> This defeats the purpose of memory mapped files.
> Shouldn't the GC be able to manage it if I keep a pointer into it.

The GC does not manage memory-mapped files. That's the job of the OS.


> I am closing them because the OS has a limit in how many it can open,
> either way the memory is still there isn't it ?

No, once you close it, the OS will remove the mapping. So when you try
to access that address, it will segfault.  This has nothing to do with
the GC, the page tables that map the memory addresses to the file are
managed by the OS.  By closing it you're basically telling the OS "I
don't need the mapping anymore", so it removes the mapping from your
page tables and that address no longer exists in your process' address
space.  So the next time you try to access it, you will get a segfault.


T

-- 
Heuristics are bug-ridden by definition. If they didn't have bugs, they'd be 
algorithms.


Re: I don't understand betterC

2023-09-01 Thread evilrat via Digitalmars-d-learn

On Friday, 1 September 2023 at 13:17:08 UTC, confused wrote:
On Friday, 1 September 2023 at 08:19:55 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
``size_t`` is defined in ``object.d`` which is implicitly 
imported into all modules.


If it cannot be found, one of three things is happening:

1) You have messed with some cli args related to picking 
druntime/phobos

2) You have defined a module called object.
3) You have a broken compiler install.


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




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

```



Re: I don't understand betterC

2023-09-01 Thread bachmeier via Digitalmars-d-learn

On Friday, 1 September 2023 at 13:17:08 UTC, confused wrote:
On Friday, 1 September 2023 at 08:19:55 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
``size_t`` is defined in ``object.d`` which is implicitly 
imported into all modules.


If it cannot be found, one of three things is happening:

1) You have messed with some cli args related to picking 
druntime/phobos

2) You have defined a module called object.
3) You have a broken compiler install.


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


I'm interested in betterC as a curiosity, and trying to explore 
the extent to which D classes and object-oriented programming 
can be preserved within its bounds (because I really like 
classes, and I really like D, and I really hate C++, and I'm 
trying to learn about bare-metal programming).


Thank you, by the way, for sharing your knowledge and time.


You can read the documentation for object.d 
[here](https://dlang.org/phobos/object.html). It's kind of 
important.


Re: I don't understand betterC

2023-09-01 Thread confused via Digitalmars-d-learn
On Friday, 1 September 2023 at 08:19:55 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
``size_t`` is defined in ``object.d`` which is implicitly 
imported into all modules.


If it cannot be found, one of three things is happening:

1) You have messed with some cli args related to picking 
druntime/phobos

2) You have defined a module called object.
3) You have a broken compiler install.


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


I'm interested in betterC as a curiosity, and trying to explore 
the extent to which D classes and object-oriented programming can 
be preserved within its bounds (because I really like classes, 
and I really like D, and I really hate C++, and I'm trying to 
learn about bare-metal programming).


Thank you, by the way, for sharing your knowledge and time.


Re: I don't understand betterC

2023-09-01 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
``size_t`` is defined in ``object.d`` which is implicitly imported into 
all modules.


If it cannot be found, one of three things is happening:

1) You have messed with some cli args related to picking druntime/phobos
2) You have defined a module called object.
3) You have a broken compiler install.