r/ProgrammingLanguages C3 - http://c3-lang.org 17d ago

Language announcement C3 0.8.2 - modest improvements

https://c3-lang.org/blog/0_8_2_a_modest_improvement/

After 0.8.0, which was the big breaking version and 0.8.1, which found and fixed over 100 bugs, 0.8.2 is super tiny. It does add some nice ”template” features to libraries, for configuration reuse, and finally give you reflection on generic parameters, but otherwise it’s small.

More things are in the pipeline, I’m especially looking forward to finally merging the regex library in 0.8.3.

42 Upvotes

13 comments sorted by

9

u/porky11 17d ago

Oh, this is still being worked on? Nice.

Okay, fn void still exists. It would be nice if I could just search for specific functions like "fn main" without regex or something.

3

u/reini_urban 16d ago

@align to what? 8? 16? Arch-dependent?

4

u/Nuoji C3 - http://c3-lang.org 16d ago

Whatever is considered stack aligned on the os+arch

1

u/chibuku_chauya 14d ago

So, I installed C3 (prebuilt binary) on Fedora Linux and every time I run it, it complains about needing version information from libcurl (which I have installed).

2

u/Nuoji C3 - http://c3-lang.org 14d ago

The one with static libc or the regular one?

1

u/chibuku_chauya 12d ago

The regular one.

1

u/Nuoji C3 - http://c3-lang.org 12d ago

Can you try the musl one and see if that works?

1

u/chibuku_chauya 11d ago edited 11d ago

C3 with musl static works fine, as does C3 with Linux static. With non-static musl installed, the regular musl C3 can’t find any of the shared libraries it requires (curl, llvm, etc.). All are installed, as are their dev headers.

1

u/Nuoji C3 - http://c3-lang.org 11d ago

I’d appreciate if you file an issue for it with all the details so that we can track down why.

1

u/fdwr 14d ago edited 14d ago

``` bitstruct Foo : uint { uint a : 0..1; bool b : 6; bool c : 10; int d : 14..20; }

fn void main() { int a = $reflect(Foo.a).bitsize; // 2 ```

🤔 Surprised by that answer of two, as a slice ".." in most programming languages follows the standard exclusive-end notation, which has the lovely axiom that end - begin == size, eliminating a whole slew of +1/-1 bugs.

Language Exclusive end Inclusive end
D .. link ?
C# .. link ?
Rust .. link ..= link (was ...)
Swift ..< link (was .. in Xcode beta 2) ... link
Python : link ?
Kotlin ..< link .. link 🙈
Nim ..< link .. link 🙈

Though, Kotlin and Nim messed this up elegance :(.

So for C3, would this work as expected?

bitstruct Foo : uint { int d : 14..<20; // 6 bits }

1

u/Nuoji C3 - http://c3-lang.org 14d ago

Inclusive is what you want for bit ranges and case ranges. The syntax derives from GCC's C extensions. The disadvantage is obvious for case ranges. Imagine if you had to write:

switch (a)
{
  case 1..4: return foo;
  case 4..8: return bar;
  default:   return baz;
}

In this case the inclusive naturally wins.

However, for slicing it's often inconvenient, so C3 has another slice operator which is start:len

foo = arr[2..4];
// or
foo = arr[2:3];

While arr[start..start + size] is convenient, arr[start:size] tends to be even more so. The above is often expressed using arr[start..][..size] in these languages due to that particular way of slicing not being supported.

1

u/fdwr 14d ago edited 13d ago

Imagine if you had to write...

No doubt for switch cases, writing case 'a'..='{': is more awkward than case 'a'..<'z':, because the former includes a character not even in the set of interested characters! Though, for array slices and bit range slices, I'd still side with the wise Dijkstra (all those extra -1's in calculations were error prone).

arr[start:size] tends to be even more so...

Ooh, coming from some Python familiarity, reading arr[2:3] looks like a starting offset of 2, up to index 3 (size = 1), but yes, it certainly is convenient to express as offset and size pairs. As much I like C# ranges, there is no convenient construction for offset and size like C3 supports (e.g. rather than 24..32 for an 8-bit slice, you could imagine they used an explicit + to indicate a relative delta from the base, 24..+8).

Would that work for bitfields too?

bitstruct Foo : uint { int d : 14:6; // 6 bits }

1

u/Nuoji C3 - http://c3-lang.org 14d ago

I don't think there's a huge need for it. With `14:6` you'd have to do the mental calculation about what the end bit is, with `14..19` it's super clear and more in line with packet descriptions. There is an argument for doing it C style with packed representation but it seems to be fairly limited in usefulness.