1. 4
    1. 5

      In my opinion, this needs the “rant” tag. This reads as a C++ programming bitching about C not being C++. Looking at the code in question, it’s fine; I’ve seen (and worked with) way worse in my time (int, long and X* are all 32 bits in size and interchangable, for instance). The only time I end up using void * is when I use functions like qsort() or bsearch() or similar style functions (and even then, it’s not bad (unless you aren’t used to it and void * jumps out at you in code like this).

      Portability with ifdef is unfortunate, and I personally try to avoid it but there are cases where it’s unavoidable, like this example from my own code (and to the author’s point, I don’t own a Solaris system to test this, but I do know of an organization using this code currently, so it stays).

      The author goes on to complain about build systems in a rant about C, and then goes into some build took the author likes written in C++. Okay, we get it! C is not C++.

      1. 1

        A little bit, yeah. It starts off good but quickly veers off-track of goaccess itself. They’re reasonably correct about the void *‘s being overused, there’s a good double handful of functions that take void * arguments and then immediately cast them to a known pointer type for some reason. But I don’t find the ifdef’s particularly excessive and there’s not really much point in complaining about null-terminated strings in C code.

        All in all, my experience is that a skilled C programmer will commit much worse crimes without batting an eye.

        1. 1

          Where do you feel the void *‘s are being overused? If it’s in the code I linked to, that’s because of the C API to qsort() or bsearch() where it’s unavoidable (unless you want a bajillion different implementations). And as a “skilled C programmer” I don’t consider what Wayland did that much of a crime (if you are indeed talking about intrusive structures).

          1. 2

            I would expect they are talking about wl_container_of abusing memory location to get to a parent container.

            1. 1

              Yeah, this. It’s valid, it works, it makes perfect sense, but getting a pointer into the middle of a structure and saying “I know this pointer is part of a Foo so I can just back that pointer up a bit and access the rest of the Foo” still Feels Wrong.

              1. 2

                Fair enough. I do that myself, but I wrap the actual “crime” in a function. For example, from a Pascal compiler I’m writing [1]:

                else if ((tree = find_node(state,ID_VAR,state->token.value.identifier)) != NULL)
                {
                  var__s *var = var_from_tree(tree);
                

                The var_from_tree() is doing the work here, and it’s defined as:

                static inline var__s *var_from_tree(tree__s *tree)
                {
                  return (var__s *)(((char *)tree) - offsetof(var__s,tree));
                }
                

                C has offsetof() for a reason. (Note: I’m using an intrusive tree structure in my var structure in case it’s not clear.)

                [1] For an 8-bit CPU, in my spare time. I’ve been working on it for a few years now. No hurry to complete it.

          2. 1

            The example given: find_color_in_list() and related functions. There’s also a few other functions that do similar things: start_server() and read_data() in gwsocket.c and probably one or two others right now. Upon inspection they miiiiiiight be that way ‘cause they’re used as generic callbacks? If that’s the case, then that’s just what you gotta do and you can’t really blame the victim there.

        2. 1

          Wait a wayland seat isn’t allowed to have more than one keyboard?

          1. 2

            That was the case last time I checked? The seat is also not a fundamental Wayland concept, it’s an abstraction that wlroots provides for you.

    2. 3

      “Opinions I Already Had Projected on Some C Code”

      Some of these things are obviously bad, but… vendor all libraries? Statically link everything? Just never have platform-specific code of any kind? Okay then. Some of us have to work in the real world, and the “real world” for most C code isn’t nodejs or go or whatever.

      C obviously has its problems, but when you’re too hung up on programming languages and go into things with a “the language is the problem here in all cases” mentality, you end up having silly positions and writing entire articles like this one that can be condensed down into “all the problems in this project would be fixed if it were rewritten in C++, a language which not only doesn’t prevent any of them, but notoriously shares most of the problems I’m complaining about because the platform/build-system/deployment situation is identical”.

      The Internet needs a bot that just posts a weekly article with the title “C Bad” and no content whatsoever. It would save us all a lot of time.