Computer Old Farts Forum
 help / color / mirror / Atom feed
From: Derek Fawcus <dfawcus+lists-coff@employees.org>
To: COFF <coff@minnie.tuhs.org>
Subject: [COFF] Zig (was Re: more about Brian... [really Rust])
Date: Sat, 5 Feb 2022 23:09:19 +0000	[thread overview]
Message-ID: <Yf8Dn62NjiIaozmc@clarinet.employees.org> (raw)
In-Reply-To: <CAEoi9W4U7PpBGPT5U3k_XLoxBrceUDAHuB7ykZYQb9TxAD0x+Q@mail.gmail.com>

On Fri, Feb 04, 2022 at 06:18:09PM -0500, Dan Cross wrote:
> [TUHS to Bcc, +COFF <coff@minnie.tuhs.org> ]
> 
> This isn't exactly COFF material, but I don't know what list is more
> appropriate.
> 

[snip]

> However, right now? I think it
> sits at a local maxima for systems languages targeting bare-metal.

Have you played with Zig?  I've only just started, but it does seem to
be trying to address a number of the issues with C ub, and safety, 
while sticking closer to the 'C' space vs where I see Rust targetting
the 'C++' space.

It doesn't have Rust's ownership / borrow checker stuff, it does seem
to have bounds checking on arrays.

e.g. the UB for multiply example you give ends up as a run time panic
(which I suspect can be caught), or one can use a different (wrapping)
multiply operator similar to in Rust.

i.e. see the below test program and its output.

DF

$ cat main.zig
const std = @import("std");

pub fn mulOverflow(a: u16, b: u16) u16 {
    return a * b;
}

pub fn mulWrap(a: u16, b: u16) u16 {
    return a *% b;
}

pub fn main() void {
    const result1 = mulWrap(65535, 4);
    std.debug.print("mulWrap is {d}\n", .{result1});

    const result2 = mulOverflow(65535, 4);
    std.debug.print("mulOverflow is {d}\n", .{result2});
}

$ ./main
mulWrap is 65532
thread 32589 panic: integer overflow
/home/derek/Code/zig-play/main.zig:4:14: 0x2347bd in mulOverflow (main)
    return a * b;
             ^
/home/derek/Code/zig-play/main.zig:15:32: 0x22cfda in main (main)
    const result2 = mulOverflow(65535, 4);
                               ^
/usr/local/zig-linux-x86_64-0.9.0/lib/std/start.zig:543:22: 0x225d5c in std.start.callMain (main)
            root.main();
                     ^
/usr/local/zig-linux-x86_64-0.9.0/lib/std/start.zig:495:12: 0x20713e in std.start.callMainWithArgs (main)
    return @call(.{ .modifier = .always_inline }, callMain, .{});
           ^
/usr/local/zig-linux-x86_64-0.9.0/lib/std/start.zig:409:17: 0x2061d6 in std.start.posixCallMainAndExit (main)
    std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp }));
                ^
/usr/local/zig-linux-x86_64-0.9.0/lib/std/start.zig:322:5: 0x205fe2 in std.start._start (main)
    @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{});
    ^
Aborted

$ zig build-exe -O ReleaseFast main.zig
$ ./main
mulWrap is 65532
mulOverflow is 65532
$ zig build-exe -O ReleaseSafe main.zig
$ ./main
mulWrap is 65532
thread 32608 panic: integer overflow
Aborted

-- 

_______________________________________________
COFF mailing list
COFF@minnie.tuhs.org
https://minnie.tuhs.org/cgi-bin/mailman/listinfo/coff

  reply	other threads:[~2022-02-05 23:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <c0fd1aec-55a8-54a4-94dc-748068d9e15d@gmail.com>
     [not found] ` <202202011537.211FbYSe017204@freefriends.org>
     [not found]   ` <20220201155225.5A9541FB21@orac.inputplus.co.uk>
     [not found]     ` <202202020747.2127lTTh005669@freefriends.org>
     [not found]       ` <7C19F93B-4F21-4BB1-A064-0307D3568DB7@cfcl.com>
     [not found]         ` <1nFWmo-1Gn-00@marmaro.de>
     [not found]           ` <CAP2nic37m2aSCffgr8o_J+BkAbnrzFDUaHX9V0brd+L8+PqdPA@mail.gmail.com>
     [not found]             ` <202202040234.2142YeKN3307556@darkstar.fourwinds.com>
2022-02-04 23:18               ` [COFF] [TUHS] more about Brian... [really Rust] Dan Cross
2022-02-05 23:09                 ` Derek Fawcus [this message]
2022-02-06 12:32                   ` [COFF] Zig Ralph Corderoy
2022-02-06 12:49                   ` [COFF] Zig (was Re: more about Brian... [really Rust]) Dan Cross
2022-02-06 15:42                   ` Adam Thornton
     [not found]             ` <CALMnNGjfvtd=6qsmT6kXm3eEBM7OhhGSJ4Wbbjiv+B9P9rLafA@mail.gmail.com>
     [not found]               ` <alpine.DEB.2.21.2202040304380.28373@sd-119843.dedibox.fr>
     [not found]                 ` <CAD2gp_Rn_==vzUw80geH7ryLwmU+uiCidQVfMLn51HhZV1VHfA@mail.gmail.com>
     [not found]                   ` <e201372274da4ed9cf75bcaaf43a5d95@firemail.de>
     [not found]                     ` <1644006490.2458.78.camel@mni.thm.de>
     [not found]                       ` <20220206005609.GG3045@mcvoy.com>
     [not found]                         ` <21015c2c-2652-bbc3-dbd7-ad3c31f485a2@gmail.com>
     [not found]                           ` <CAKzdPgzSH94Xg=XYYKy6J+dWAD+ZVDzUTNE=YNRkyVRH69PJfA@mail.gmail.com>
     [not found]                             ` <CACYmRNDzrSvbwnAEAVz=REsdqSs675_pkBhi5dm5iWRCwRVo=A@mail.gmail.com>
     [not found]                               ` <CAKzdPgxQmB8ikjQwExOVnOwGDQrc-N==qzf=ZwhH7Ut-fD6pCg@mail.gmail.com>
     [not found]                                 ` <CACYmRNAKUYwVwbn+mXCAVyySV5sVEbZmN4wvQbQKXx-p+nKM=w@mail.gmail.com>
2022-02-06 14:13                                   ` [COFF] [TUHS] more about Brian Dan Cross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yf8Dn62NjiIaozmc@clarinet.employees.org \
    --to=dfawcus+lists-coff@employees.org \
    --cc=coff@minnie.tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).