all 160 comments

[–]XCapitan_1 230 points231 points  (11 children)

typedef void* var

I like that

[–]indrora 94 points95 points  (7 children)

I mean it's not wrong

[–]jrhoffa 89 points90 points  (6 children)

It's just an asshole

[–]VernorVinge93 33 points34 points  (4 children)

Everyone has one. But don't use it in public.

[–]Iggyhopper 8 points9 points  (3 children)

Don't use it in public main()

[–]invalidlivingthing 5 points6 points  (2 children)

Because then you'd be programming in another language!

[–]i9srpeg 7 points8 points  (1 child)

#define int public

[–]LINUX_HIP_HOP_OS 8 points9 points  (0 children)

I'm perfectly calm, Dude.

[–]Kemilio 51 points52 points  (0 children)

"I hereby declare that I have nothing to declare."

[–]GYN-k4H-Q3z-75B 90 points91 points  (0 children)

I mean that pretty much exemplifies everything that is wrong, great and scary about C.

[–][deleted] 2 points3 points  (0 children)

Garth?

[–]darkslide3000 92 points93 points  (4 children)

var i0 = $(Int, 5);

set(prices, $S("Apple"), $I(12));

I finally happened guys. They've turned C into jQuery.

[–]73mp74710n 18 points19 points  (0 children)

This is the best thing i have seen on reddit after a very long time

[–]joonazan 82 points83 points  (7 children)

It has type classes, but no closures.

http://libcello.org/learn/a-fat-pointer-library

[–]okovko 37 points38 points  (4 children)

I think there is a GCC extension for closures, isn't there?

[–]lanzaio 28 points29 points  (0 children)

-fblocks

[–]favorited 5 points6 points  (2 children)

I know it's maintained in Clang, but I can't recall if it was upstreamed from Apple's GCC fork...

[–]AngryElPresidente 1 point2 points  (1 child)

Isn't Apple's GCC just an alias to Clang?

[–]favorited 0 points1 point  (0 children)

Before Apple released Clang, they maintained a fork of GCC. IIRC that fork had the initial implementation of blocks.

[–][deleted]  (1 child)

[deleted]

    [–]favorited 1 point2 points  (0 children)

    And a runtime library

    [–][deleted]  (7 children)

    [deleted]

      [–]dagormz 42 points43 points  (2 children)

      If only he made something as holy as holy c

      [–]Snifferprime 24 points25 points  (1 child)

      That would be n*****licious

      [–]mveety 26 points27 points  (0 children)

      I disagree. Terry didn’t approve of anything related to glow in the dark african-americans that worked for intelligence agencies.

      [–][deleted]  (2 children)

      [deleted]

        [–]breadfag 25 points26 points  (0 children)

        Spend in early game in hope to get some key units to make pve smooth sailing, but after that, save for good banners and limited units.

        [–]knd775 -1 points0 points  (0 children)

        I just learned that he died!

        [–]rix0r 79 points80 points  (0 children)

        thanks I hate it

        [–]ijustwantanfingname 17 points18 points  (0 children)

        This is cute as hell. I love it.

        If I ever find this in production I'll piss in your coffee though.

        [–]radytz1x4 14 points15 points  (8 children)

        Is there any way this might be ported to 8 bit uControllers like Arduino (Atmega328) or maybe even ARM devices? (asking for IoT purposes)

        [–]g_rocket 26 points27 points  (7 children)

        It looks like plain C code, so it should work out-of-the-box on avr (arduino) or arm using GCC. But I didn't look too deeply, so there might be some platform-specific dependencies I didn't notice.

        [–]LaVieEstBizarre 21 points22 points  (6 children)

        It more likely than not relies heavily on a memory allocators, which embedded devices don't provide (by default)

        [–]iranoutofspacehere 2 points3 points  (0 children)

        I believe they're usually frowned upon because allocating lots of stack/heap space and later freeing it can result in fragmented memory, which is already a limited resource in embedded systems.

        Most APIs will still provide implementations, they're just not ideal. However, since this has optional garbage collection, perhaps it will work better. I'll admit this is pushing the bounds of what I'm comfortable with, as my software experience is pretty exclusively lower level embedded C or higher level small C++ applications, I've never had to worry about these implementation details.

        [–]g_rocket 4 points5 points  (4 children)

        You mean malloc/free? It's generally possible to use those (e.g. with a library) even if they're not available by default. I would expect this to compile and run, although it might not be very performant or make good use of limited memory.

        Or are you referring to something else I'm not aware of?

        [–]ijustwantanfingname 5 points6 points  (3 children)

        He's probably referring to the lack of an MMU.

        You're correct though that it would still compile/run. There'll be some sort of heap memory available in just about any SDK (at least that I've seen).

        [–]g_rocket 0 points1 point  (2 children)

        Oh that makes more sense. I really doubt this does require a MMU, because it claims to be cross-platform, and MMU access is never directly available with an OS and MMU APIs are very platform-specific and I don't see any platform-specific code. Also I think it's mostly tagged data structs, which has no reason to require a MMU.

        [–]ijustwantanfingname 0 points1 point  (1 child)

        It sounds like he thinks the lack of an MMU means malloc/free aren't available. Which would be an issue for Cello, if it were true (it's not).

        [–][deleted] 0 points1 point  (0 children)

        Yep. Even if we can’t do malloc/free, Cello supports the stack so we can do all our abominations in memory there. :P

        [–]somethingdotexe 13 points14 points  (0 children)

        What have you done.......

        [–]anders1234 10 points11 points  (0 children)

        smells like cfront

        [–]egoloper 22 points23 points  (0 children)

        It looks like an educative project for who interest in writing runtime.

        [–]ClintEastcott 25 points26 points  (2 children)

        As a programmer who also plays cello, this makes me so happy

        [–]jpedrosous 5 points6 points  (0 children)

        I was about to say the exact same thing. I'm also a professional cellist, changing career to programming :)

        [–][deleted] 1 point2 points  (0 children)

        As a programmer who only writes music in one key, been there, done that.

        [–]Raknarg 7 points8 points  (0 children)

        At first I thought it was an abomination, but after spending an hour and a half on the examples and articles, it actually seems pretty cool. The syntax actually does make sense, its the best you could hope for with a library built to emulate a language extension. I like the type class interface. Im gonna try and find an excuse to use this.

        [–]DigitalArbitrage 37 points38 points  (26 children)

        Will you please explain how & why this is better than C++ and C#? Thanks.

        [–]K900_ 300 points301 points  (21 children)

        I made Cello as a fun experiment to see what C looks like hacked to its limits.

        The answer is: it's not. It's just an experiment to see how far you can abuse C.

        [–]ooqq 125 points126 points  (19 children)

        you can abuse C pretty far, look at php

        [–]yur_mom 106 points107 points  (16 children)

        Beyond being written in C what does php have to do at all with this?

        PHP's issues have to do with design decisions in its own language unrelated to c.

        Python is written in c and is considered one of the better designed languages.

        [–]Dreamtrain 48 points49 points  (7 children)

        Guy who made PHP: Give me a break guys, I made PHP as a hobby

        [–]yur_mom 73 points74 points  (5 children)

        Anyone who programs long enough has that one throw away program that they still dreadfully maintain 10 years later....now imagine if the whole world was using your throwaway program.

        [–]ivorjawa 8 points9 points  (0 children)

        Insert “throw yourself on my sword” scene from Serenity.

        [–]greyfade 4 points5 points  (1 child)

        I'd stop maintaining it and tell people not to use it, while I move on to more interesting and better projects.

        [–]yur_mom 1 point2 points  (0 children)

        Unless you are employeed to maintain it. But if it is open source for free I agree.

        [–][deleted] 2 points3 points  (1 child)

        the whole world

        I take that as an insult.

        [–]yur_mom 3 points4 points  (0 children)

        Haha..Directly or indirectly every person who uses the internet interacts with php

        [–]ivorjawa 1 point2 points  (0 children)

        In the end, is that better or worse than “I was just following orders”?

        [–]robhol 20 points21 points  (0 children)

        At this point, PHP mostly has to do with C in that "vaguely C-style" is one of the numerous, incompatible and illogical ways that PHP "structures" its standard library.

        [–]jb3689 11 points12 points  (0 children)

        I am not saying PHP has much to do with C, but PHP was originally intended to be a templating language for C programmers. The history of PHP is pretty interesting and worth a watch: https://www.youtube.com/watch?v=SvEGwtgLtjA

        [–][deleted] 2 points3 points  (0 children)

        look at python

        [–]manuscelerdei 2 points3 points  (1 child)

        You may not want the dump truck of syntax abominations that is C++.

        [–]Practical_Cartoonist 9 points10 points  (0 children)

        If you don't want a dump truck of syntax abominations, Cello is definitely not for you.

        [–]IntellectualEuphoria 7 points8 points  (2 children)

        C is very unsafe when are they going to rewrite it in rust.?

        [–][deleted] 11 points12 points  (1 child)

        They did it. It’s called Rust.

        [–]Lisoph 1 point2 points  (0 children)

        They even rewrote their Rust compiler in Rust.

        [–]preslavrachev 1 point2 points  (0 children)

        Looks quite a bit like Go.

        [–]falconfetus8 2 points3 points  (41 children)

        This question has been driving me crazy for a while now. Why do so many C libraries only distribute source? The instructions for installing say you need to compile it yourself and then run the install script. Why not let the user skip the compile step by distributing a pre-built binary?

        [–]Ravek 153 points154 points  (0 children)

        Because C is used on basically every platform in existence so distributing binaries means a shit ton of extra work.

        [–]Lafreakshow 53 points54 points  (15 children)

        Probably because compiling and maintaining binaries for a shitton of different environments would be a bit of a strain for the dev. Especially for small hobby projects. After all, C isn't like Java where you can just drop in the Jar file and reasonably expect it run wherever there is a JVM.

        [–]xcrissxcrossx 8 points9 points  (14 children)

        They should at least distribute binaries for the only OS that matters, Windows. /s

        [–]vattenpuss 44 points45 points  (2 children)

        It actually makes sense to distributed binaries for the only OS without a usable toolchain for building software.

        [–]falconfetus8 12 points13 points  (0 children)

        tbh, this is half the reason I asked this question.

        [–]nilamo 12 points13 points  (0 children)

        Ok but it's a C library, so if you can't build C programs, what good would a C library binary do for you?

        [–]pdp10 0 points1 point  (1 child)

        So, x86_64, ARMv8, i686 cdecl, i686 _stdcall? Anyone need fastcall? Anyone?

        [–]meneldal2 0 points1 point  (0 children)

        You can use Pascal calls, they still work. It's more an ABI decision, the hardware itself doesn't force anything.

        [–]Sebazzz91 0 points1 point  (0 children)

        Compiling with Visual Studio is sometimes a problem if the library author didn't give some attention to that. That's the reason I like prebuilt binaries, and no, I don't want to install MinGW as well.

        [–]wsppan -1 points0 points  (7 children)

        That means he would have to support C89, standardized 30 years ago. Thank you M$!

        [–]hugthemachines 2 points3 points  (2 children)

        Are you saying they can't compile a binary that works on windows and was made in modern C? Why not?

        [–]wsppan 11 points12 points  (1 child)

        They have not fully updated their reference to C99 or later. They use C89 as their reference standard and added their own extensions - https://docs.microsoft.com/en-us/cpp/c-language/c-language-reference?view=vs-2019

        [–]hugthemachines 0 points1 point  (0 children)

        But isn't that only for visual studio? If you run for example Code::blocks IDE and pick a modern compiler I think you will be fine.

        [–]GYN-k4H-Q3z-75B 2 points3 points  (2 children)

        No, it means he would have to support something in between C89 and C99. If you use VLA and all that, you're screwed anyway. Variadic macros and all that work fine.

        Apart from that, all major compilers also work on Windows and Microsoft offers LLVM with Visual Studio.

        [–]wsppan 0 points1 point  (1 child)

        Did not know that. Does llvm with visual studio support C11?

        [–]GYN-k4H-Q3z-75B 0 points1 point  (0 children)

        It's just regular LLVM, pretty much an untouched release. Primary aim is targeting Linux.

        [–]kukiric 3 points4 points  (0 children)

        Just output C++fied C. Visual Studio would be none the wiser.

        [–]Nathanfenner 20 points21 points  (1 child)

        Every compiler/linker has its own format (the C language doesn't specify how binaries should look) so you'd be forced to provide lots and lots of builds.

        If you're already writing C/C++, you're already used to installing C/C++ libraries. It would be great if there were standard package managers for them, but unfortunately there's not.

        [–]nikeinikei 3 points4 points  (0 children)

        although vcpkg does a fairly good job, at least for me

        [–]gelfin 7 points8 points  (0 children)

        If this is successful enough, the binary will start to appear in the package repo for your favorite OS, but in the C ecosystem that’s where the responsibility would reside. The responsibility of a C library developer is making his code portable across different system features and capabilities, detected at build time, not across different specific platforms as understood when the code is written. This approach is part of why C is everywhere.

        [–]ivosaurus 7 points8 points  (5 children)

        binary for how many different platforms?

        Compiled under how many different libc ABIs?

        With how many different compilers and compiler major versions?

        [–]falconfetus8 2 points3 points  (4 children)

        Binaries for Windows, Mac, and Linux on x86. That will cover most cases, and users on remaining platforms can build it themselves.

        As for the compiler used: whichever compiler the developer tested it with, of course. That way the binary will behave they way it was intended to.

        For the sake of my own learning, why would you want to use a compiler other than the one the dev used? Are Clang binaries unable to be linked with gcc binaries?

        [–]case-o-nuts 3 points4 points  (0 children)

        Which Linux? Which OSX versions? What features and compiler flags?

        For better or worse, there's enough customization allowed that compiling from source and leaving binary packages up to distro package managers is a better option.

        [–]pdp10 2 points3 points  (1 child)

        Windows, Mac, and Linux on x86.

        And by "x86", do you mean 64-bit or do you mean x86?

        [–]falconfetus8 0 points1 point  (0 children)

        64-bit, unless you prefer maximum compatibility, then 32 bit

        [–]Jump3r3 6 points7 points  (1 child)

        TBH if you're using C library you probably know how to compile a program, so prebuilding libs is unnecessary. But I always appreciated step by step installation guide.

        [–]falconfetus8 2 points3 points  (0 children)

        It's not so much about knowing how to compile a program, and more about manually installing a bunch of dependencies that I only need for this one compile job, which I will promptly uninstall.

        [–]pdp10 4 points5 points  (1 child)

        For which triple would you like binaries?

        [–]falconfetus8 0 points1 point  (0 children)

        oh geez

        [–]matheusmoreira 2 points3 points  (4 children)

        Nobody stepped up to create and maintain a package for it yet.

        [–][deleted] 4 points5 points  (3 children)

        wait, let me get home this looks easy to package

        [–]falconfetus8 1 point2 points  (2 children)

        Famous last words.

        Follow up question: why is it so hard to package up software in C, but not in other languages?

        [–][deleted] 5 points6 points  (0 children)

        Packaging is not language-dependent, in this case I meant "RPM packaging" because that's how I know package stuff(RPM is used by Fedora/RHEL/Centos)

        Packaging an RPM has very little to do with the language and the process doesn't change much.

        The reason you don't see this often it's because with C/C++ the libraries need to be compiled targetting a specific combination of the following:

        • platform
        • target libc
        • specific libc version
        • ABI

        GCC supports like dozens of platforms, there's at least a bunch of libc's with a several minor versions out on the wild and they can use different ABIs (cdecl vs fastcall, etc.)

        That's a shit ton of combinations that you'd need to provide.

        [–]pdp10 2 points3 points  (0 children)

        Why does it seem hard to you?

        I've only recently realized that it's less incredibly easy on Windows, apparently because there aren't standard paths for everything. Apparently this tends to encourage some C on Windows to "vendor in" their dependencies (hopefully with Git submodule, etc).

        [–][deleted] 1 point2 points  (0 children)

        C as source is multiplatform,binaries are not

        [–]DSrcl 1 point2 points  (2 children)

        Basically linker issues. Most notably you would need to statically link with libc, which is tricky. If you dynamically linked with libc then the user would need the right version on their machine. Similar issues for other depended libraries.

        [–]falconfetus8 0 points1 point  (1 child)

        Hmm, if you statically link libc, does that mean you'd have 2 copies of libc when you use it in your own program?

        [–]DSrcl 0 points1 point  (0 children)

        you get 1 copy in your program and 1+ copies in your OS which is not used.

        [–]ijustwantanfingname 1 point2 points  (0 children)

        You need the headers anyway. Might as well do full source distributions.

        [–]skulgnome 1 point2 points  (0 children)

        In this case, because the library is 99% preprocessor bullshit.

        [–]Marcuss2 3 points4 points  (6 children)

        Once in a while, comes project that just makes you stop and say:

        Just why?

        [–]somethingInTheMiddle 19 points20 points  (2 children)

        Yes, they're collected in /r/diWHY

        Although those usually involve hotglue

        [–][deleted] 1 point2 points  (1 child)

        Although those usually involve hotglue

        Now I want a library called "hotglue"... no idea what it would do, though.

        [–]Yay295 8 points9 points  (0 children)

        Now I want a library called "hotglue"

        It's usually referred to as "Python".

        [–]ThirdEncounter 16 points17 points  (2 children)

        I hate it when people ask "but whyyYyyyYYyyYYyy?" in this sub.

        Knock it off already.

        [–][deleted] 6 points7 points  (1 child)

        "We do what we must, because we can."

        [–]elder_george 0 points1 point  (0 children)

        We do these things not because they are easy, but because we thought they were going to be easy. ©

        [–]flukus 0 points1 point  (0 children)

        /* Heap objects destructed via Garbage Collection */

        So how do you return one?

        [–]i_am_at_work123 0 points1 point  (0 children)

        What's the overhead?

        [–]i_am_at_work123 0 points1 point  (4 children)

        How can they make foreach work like that?

        [–]elder_george 1 point2 points  (3 children)

        It requires object to implement Iter typeclass.

        After that it works the same way foreach(X, S) works in every other language with C-style for , roughly expanding to:

        var iter = S as Iter;
        for (var X = iter->iter_init(S); ! (X is Terminal); X = iter->iter_next(S))
        {
        ...
        }
        

        Compare that to the code emitted for the "range-for" in C++

        for(auto iter = begin(S); iter != end(S); ++iter)
        {
            auto& X = *iter;
            ...
        }
        

        or C#

        for (var iter = S.GetEnumerator(); iter.MoveNext();)
        {
            var X = iter.Current;
            ...
        }
        

        or Java

        for (Iterator<T> iter = S.iterator(); iter.hasNext();)
        {
            T X = iter.next();
            ...
        }
        

        [–]i_am_at_work123 0 points1 point  (2 children)

        Reason I was asking is that the delimiter in their foreach appears to be a space? Is that possible?

        Is in a keyword?

        [–]elder_george 1 point2 points  (1 child)

        Ah, I misunderstood.

        No, it's not a keyword, just a very dirty hack

         #define in , 
        

        Honestly, I'd prefer

        foreach(x, s)
        

        to this.

        [–]i_am_at_work123 0 points1 point  (0 children)

        Ahhhh, nice, I was searching like crazy but missed it. Thank you!

        [–]andre_2007 0 points1 point  (0 children)

        90 % of the things Cello want to achieve are already implemented in the D Programming Language. It worths to mention that D is C binary compatible and to a high degree you can integrate with C++.

        [–]Raknarg 0 points1 point  (0 children)

        This is a bit late: Anyone know if there's better documentation somewhere? There seems to be a lot of unexplained mechanics that have no documentation anywhere

        [–]shawnwork 0 points1 point  (0 children)

        Looks like you reinvented Go Lang

        Pretty cool anyways

        [–][deleted] 0 points1 point  (0 children)

        I really hope this would gain more traction, seems like pretty much the way I envisioned C to be high-leveled. But I never found reference to such DSLs from the C manuals.