www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - BetterC unexpected results

reply DLearner <bmqazwsx123 gmail.com> writes:
I thought dynamic arrays were unavailable under -betterC.

Example_02:
```
extern(C) void main() {
    import core.stdc.stdio : printf;
    int[] A;
    printf("Hello betterC\n");
}
```

```
dmd -betterC -run Example_02
```

Expected result: Failure at compilation stage, owing to presence 
of dynamic array A, when -betterC set.
Actual result: Ran to completion, dislaying the message.

Example_03:
```
void main() {
    import core.stdc.stdio : printf;
    int[] A;
    printf("Hello betterC\n");
}
```

```
dmd -betterC -run Example_03
```

Expected result: Failure at compilation stage, owing to presence 
of dynamic array A, when -betterC set.
Actual result: Failed at link (not compilation) stage.
Jan 08 2023
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Dynamic arrays are not.

Slices are.

A slice is a pointer + length pair; it requires no runtime 
infrastructure to manipulate.

A dynamic array, has slices that reference internal state in the GC 
which is where all the manipulation takes place (like appending).
Jan 08 2023
prev sibling next sibling parent areYouSureAboutThat <areYouSureAboutThat gmail.com> writes:
On Sunday, 8 January 2023 at 13:49:22 UTC, DLearner wrote:
 I thought dynamic arrays were unavailable under -betterC.
 .. ...
See the 'Retained Features' section, and the 'Unavailable Features' section https://dlang.org/spec/betterc.html
Jan 08 2023
prev sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Sunday, 8 January 2023 at 13:49:22 UTC, DLearner wrote:
 I thought dynamic arrays were unavailable under -betterC.

 Example_02:
 ```
 extern(C) void main() {
    import core.stdc.stdio : printf;
    int[] A;
    printf("Hello betterC\n");
 }
 ```

 ```
 dmd -betterC -run Example_02
 ```

 Expected result: Failure at compilation stage, owing to 
 presence of dynamic array A, when -betterC set.
 Actual result: Ran to completion, dislaying the message.

 Example_03:
 ```
 void main() {
    import core.stdc.stdio : printf;
    int[] A;
    printf("Hello betterC\n");
 }
 ```

 ```
 dmd -betterC -run Example_03
 ```

 Expected result: Failure at compilation stage, owing to 
 presence of dynamic array A, when -betterC set.
 Actual result: Failed at link (not compilation) stage.
That example is working for me What's the exact code you wrote?
Jan 08 2023
parent reply DLearner <bmqazwsx123 gmail.com> writes:
On Sunday, 8 January 2023 at 23:59:21 UTC, ryuukk_ wrote:
[...]
 Example_03:
 ```
 void main() {
    import core.stdc.stdio : printf;
    int[] A;
    printf("Hello betterC\n");
 }
 ```

 ```
 dmd -betterC -run Example_03
 ```

 Expected result: Failure at compilation stage, owing to 
 presence of dynamic array A, when -betterC set.
 Actual result: Failed at link (not compilation) stage.
That example is working for me What's the exact code you wrote?
``` void main() { import core.stdc.stdio : printf; int[] A; printf("Hello betterC\n"); } ``` Result: ``` C:\Users\SoftDev\Documents\BDM\D\BetterC>dmd -betterC -run Example_03 lld-link: error: undefined symbol: __d_run_main
 referenced by Example_03.obj:(_main)
Error: linker exited with status 1 ``` Compiler version: ``` C:\Users\SoftDev\Documents\BDM\D\BetterC>dmd --version DMD32 D Compiler v2.100.2-dirty ```
Jan 11 2023
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Makes sense, you wrote a main function which only applies to having a 
druntime.

For -betterC, use the libc's main function:

```d
extern(C) void main() {

}
```
Jan 11 2023