August 30, 2017 Re: D as a Better C | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | How should command-line arguments be used in better C ? Looping through argv seems to print environment variables : import core.stdc.stdio; extern(C) int main(int argc, char*[] argv, char*[] env) { foreach(i; 0 .. argc) printf("arg %d: %s\n", i, argv[i]); return 0; } Compiling with v2.076.0-b2-dirty on Lubuntu 14.04 and running with one argument outputs the following : arg 0: XDG_VTNR=7 arg 1: LC_PAPER=fr_FR.UTF-8 |
August 30, 2017 Re: D as a Better C | ||||
---|---|---|---|---|
| ||||
Posted in reply to Azi Hassan | On Wednesday, 30 August 2017 at 22:22:23 UTC, Azi Hassan wrote:
> How should command-line arguments be used in better C ? Looping through argv seems to print environment variables :
>
> import core.stdc.stdio;
>
> extern(C) int main(int argc, char*[] argv, char*[] env)
> {
> foreach(i; 0 .. argc)
> printf("arg %d: %s\n", i, argv[i]);
> return 0;
> }
>
>
> Compiling with v2.076.0-b2-dirty on Lubuntu 14.04 and running with one argument outputs the following :
>
> arg 0: XDG_VTNR=7
> arg 1: LC_PAPER=fr_FR.UTF-8
Forgot to mention, char*[] env was only for testing purposes. The code still produces the same output with char*[] env omitted.
|
August 30, 2017 Re: D as a Better C | ||||
---|---|---|---|---|
| ||||
Posted in reply to Azi Hassan | On Wednesday, 30 August 2017 at 22:22:23 UTC, Azi Hassan wrote:
> extern(C) int main(int argc, char*[] argv, char*[] env)
That's a D array of pointers. A D array is larger than a C "array" argument, thus you're skipping past it.
The correct declaration is (int argc, char** argv, char** env).
(I'd argue that is the correct way to write it in C too, that's how I always do and it works there. But I just loathe C's arrays anyway.)
|
August 31, 2017 Re: D as a Better C | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | I think "betterC" can be a good tool to use D on embedded systems, keep as few dependencies as possible, a low ROM footprint and a good C interoperability. I'll try to find some time to play with it. |
September 01, 2017 Re: D as a Better C | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Wednesday, 30 August 2017 at 22:48:45 UTC, Adam D. Ruppe wrote:
> On Wednesday, 30 August 2017 at 22:22:23 UTC, Azi Hassan wrote:
>> extern(C) int main(int argc, char*[] argv, char*[] env)
>
> That's a D array of pointers. A D array is larger than a C "array" argument, thus you're skipping past it.
>
> The correct declaration is (int argc, char** argv, char** env).
>
> (I'd argue that is the correct way to write it in C too, that's how I always do and it works there. But I just loathe C's arrays anyway.)
Brilliant, thanks ! I just re-read the blog post and it uses the char** syntax too, but I didn't pay attention to it.
|
September 07, 2017 Re: D as a Better C | ||||
---|---|---|---|---|
| ||||
Posted in reply to Parke | On Monday, 28 August 2017 at 22:45:01 UTC, Parke wrote: > When I write "hello world" in C, the executable is 8,519 bytes. > When I write "hello world" in D, the executable is 100 times larger: 865,179 bytes. > > Interestingly, "hello world" in C, compiled statically, yields 908,608 bytes. And "hello world" in assembly yields 368 bytes. https://forum.dlang.org/post/tmofjecvnqdthvetezfp@forum.dlang.org - an example for elf target. |
September 07, 2017 Re: D as a Better C | ||||
---|---|---|---|---|
| ||||
Posted in reply to Claude | On Thursday, 31 August 2017 at 13:17:36 UTC, Claude wrote:
> I think "betterC" can be a good tool to use D on embedded systems, keep as few dependencies as possible, a low ROM footprint and a good C interoperability.
>
> I'll try to find some time to play with it.
I agree, embedded systems is one of the reasons I think betterC is a good idea.
|
Copyright © 1999-2021 by the D Language Foundation