Jump to page: 1 2
Thread overview
I don't understand betterC
Aug 31
confused
Sep 01
confused
Sep 01
confused
Sep 01
bachmeier
Sep 02
confused
Sep 02
bachmeier
Sep 01
evilrat
Sep 02
confused
Sep 04
confused
Sep 04
evilrat
Sep 08
rempas
Sep 02
ryuukk_
Sep 02
confused
Sep 02
evilrat
August 31

I decided to try out betterC with the most trivial example I could think of, but why doesn't this work?

extern(C) int main()
{
	char[] hello = "hello";
	printf(hello);

	return 0;
}
September 01
```d
extern(C) int main()
{
    import core.stdc.stdio;

    string hello = "hello";
    printf(hello.ptr);

    return 0;
}
```

1) You forgot to import ``core.stdc.stdio``
2) String literal is of type string (which is an alias to ``immutable(char)[]``).
3) A slice is a pointer + length, and C doesn't understand slices, so you must explicitly pass in the pointer from the slice (the compiler would do this for you if you had the literal in the arguments list instead of the variable).
September 01

On Thursday, 31 August 2023 at 18:42:57 UTC, Richard (Rikki) Andrew Cattermole wrote:

>
extern(C) int main()
{
    import core.stdc.stdio;

    string hello = "hello";
    printf(hello.ptr);

    return 0;
}
  1. You forgot to import core.stdc.stdio
  2. String literal is of type string (which is an alias to immutable(char)[]).
  3. A slice is a pointer + length, and C doesn't understand slices, so you must explicitly pass in the pointer from the slice (the compiler would do this for you if you had the literal in the arguments list instead of the variable).
import core.stdc.stdio;

This generates Error: undefined identifier `size_t`.

September 01
``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.
September 01

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.

September 01

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. It's kind of important.

September 01

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

// 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
September 02

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 ;)

September 02

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.

September 02

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?

« First   ‹ Prev
1 2