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;
}
Thread overview |
---|
August 31 I don't understand betterC | ||||
---|---|---|---|---|
| ||||
I decided to try out betterC with the most trivial example I could think of, but why doesn't this work?
|
September 01 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to confused | ```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 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard (Rikki) Andrew Cattermole | On Thursday, 31 August 2023 at 18:42:57 UTC, Richard (Rikki) Andrew Cattermole wrote: >
This generates |
September 01 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to confused | ``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 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard (Rikki) Andrew Cattermole | On Friday, 1 September 2023 at 08:19:55 UTC, Richard (Rikki) Andrew Cattermole wrote: >
If it cannot be found, one of three things is happening:
I have in fact defined a module called 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 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to confused | 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: >
If it cannot be found, one of three things is happening:
I have in fact defined a module called 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 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to confused | 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: >
If it cannot be found, one of three things is happening:
I have in fact defined a module called It is shadowing default implicit "import object;", here a demonstration
|
September 02 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to confused | 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: >
If it cannot be found, one of three things is happening:
I have in fact defined a module called 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 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to bachmeier | 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 Re: I don't understand betterC | ||||
---|---|---|---|---|
| ||||
Posted in reply to ryuukk_ | 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 So I guess my next question is why, exactly, classes can, in fact, be implemented in |