August 23, 2017
On Wednesday, 23 August 2017 at 16:17:57 UTC, SrMordred wrote:
> On Wednesday, 23 August 2017 at 15:53:11 UTC, Walter Bright wrote:
>> On 8/23/2017 7:10 AM, Steven Schveighoffer wrote:
>>> It's only if you do something that needs the runtime, such as static ctors, or use the GC.
>>
>> Or use asserts, or even declare a struct.
>
> No structs in -betterC ???

IIUC, Steven's question was about the need for the `-betterC` switch - in his small example there was no need for it. Walter pointed out that without -betterC using structs cause link-time references to druntime, which are avoided by the use of the `-betterC` switch.
Though, one particular thing that doesn't work in `-betterC` w.r.t. structs is RAII. You can still call manually the destructor, but that's a crude hack. Work on RAII for `-betterC` is work in progress.
August 23, 2017
On Wednesday, 23 August 2017 at 13:12:04 UTC, Mike Parker wrote:
> To coincide with the improvements to -betterC in the upcoming DMD 2.076, Walter has published a new article on the D blog about what it is and why to use it.

I like this concept of "upward compatibility," -- although opposed to backward it should be phrased "forward."

Will share also this one on LinkedIn...
I see D has official account on Facebook, Twitter, Reddit... No interest in LinkedIn? I think it can also be a good promotion platform for D.
August 23, 2017
On 8/23/2017 6:12 AM, Mike Parker wrote:
> The blog:
> 
> https://dlang.org/blog/2017/08/23/d-as-a-better-c/
> 
> Reddit:
> https://www.reddit.com/r/programming/comments/6viswu/d_as_a_better_c/

Now on the front page of news.ycombinator.com !
August 23, 2017
On Wednesday, 23 August 2017 at 14:00:34 UTC, Walter Bright wrote:
> One of the reasons people use C is to get that small footprint. This has been a large barrier to C programs making use of D.

Not a better C, but intermediate D has small footprint for me too.
7.5kb totext.exe (encodes stdin to base64 and writes to stdout) - wrote it to put images in xml for opensearch descriptions.
12.5kb retab.exe (retabifies source code with various features)
5.5kb keepower.exe (manages screen saver and power settings because of obnoxious domain policy)
14.5kb fsum.exe (computes various hash sums of a file)

Additional features: string switch, array cast. Also how assert failure works in C? Mine shows a nice formatted message.
August 23, 2017
On Wednesday, 23 August 2017 at 14:01:30 UTC, jmh530 wrote:
>
> Great piece.
>
> It might be useful to beef up the documentation on some of the things that betterC changes. For instance, here
> http://dlang.org/dmd-windows.html#switch-betterC
> links to TypeInfo, which has like one line of explanation of what it's for, and ModuleInfo isn't linked to at all (and I'm still a little unclear on what that does).


Am I correct that betterC requires main to be extern(C) and must act like a C main (i.e. no void return)?

Is that something that can be changed in the future? For instance, the simplest change would be if the compiler knows that its betterC, then it can insert extern(C) to main. A second adjustment could potentially to re-write D's void main's to int and add in a return. The first seems like a good idea superficially, but I'm not 100% on the second.
August 23, 2017
On 8/23/17 11:56 AM, Walter Bright wrote:
> On 8/23/2017 7:10 AM, Steven Schveighoffer wrote:
>> Nope.
> 
> A ModuleInfo is generated, as well as FMB/FM/FME sections. Those sections may not work with the C runtime.

My point was simply that your small example doesn't cause any runtime or link time errors. You need something more complicated to require betterC.

Not sure if ModuleInfo is generated. IIRC, Martin made it so it's not if no usage of the ModuleInfo is apparent.

Yes, adding a struct causes link errors, but not because of ModuleInfo, it's because of the expected TypeInfo.

-Steve
August 23, 2017
On 8/23/17 11:52 AM, Walter Bright wrote:
> On 8/23/2017 7:24 AM, Steven Schveighoffer wrote:
>> Looks like there are some outstanding requests to be fulfilled before it's pulled.
> 
> I don't agree that the requests improve matters.

You may want to mention that in the PR. Right now it just looks like you haven't seen or responded to the requests.

-Steve
August 23, 2017
On 8/23/2017 10:26 AM, jmh530 wrote:
> Am I correct that betterC requires main to be extern(C) and must act like a C main (i.e. no void return)?

Yes.

> Is that something that can be changed in the future?

Yes, but I don't see a need for it.
August 23, 2017
On 8/23/2017 10:17 AM, Kagamin wrote:
> Also how assert failure works in C?

It calls the C assert failure function.

August 23, 2017
On 8/23/17 11:59 AM, Walter Bright wrote:
> On 8/23/2017 7:37 AM, Steven Schveighoffer wrote:
>> How do dynamic closures work without the GC?
> 
> They don't allocate the closure on the GC heap. (Or do I have static/dynamic closures backwards?)

I thought "closure" means allocating the stack onto the heap so you can return the delegate with its context intact.

From https://en.wikipedia.org/wiki/Closure_(computer_programming) :

"A language implementation cannot easily support full closures if its run-time memory model allocates all automatic variables on a linear stack. In such languages, a function's automatic local variables are deallocated when the function returns. However, a closure requires that the free variables it references survive the enclosing function's execution. Therefore, those variables must be allocated so that they persist until no longer needed, typically via heap allocation, rather than on the stack, and their lifetime must be managed so they survive until all closures referencing them have are no longer in use."

-Steve