• tobogganablaze@lemmus.org
    link
    fedilink
    English
    arrow-up
    33
    ·
    2 months ago

    If I had a penny for every pixel … I’d have around $1088. Which I would take, but really it’s not enough.

  • SpaceNoodle@lemmy.world
    link
    fedilink
    arrow-up
    28
    ·
    2 months ago

    I don’t think I’ve ever explicitly gone four deep. Two is common enough, and three happens on some rare occasions, but four seems like sheer madness.

  • xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    21
    ·
    2 months ago

    Once your pointer definition looks like a censored swear word you’re doing something awful.

    In my entire programming career I’ve used int ** less than a handful of times and I’ve always been borderline about refactoring when I need it.

    • CanadaPlus@lemmy.sdf.org
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      2 months ago

      Okay, but what if you’re dealing with a rather high-dimensional tensor? In some kinds of coding it can happen, and you usually don’t want to sacrifice performance when it does.

      You can also do increasingly elaborate pointer arithmetic, but that seems worse, not better to me.

  • MajinBlayze@lemmy.world
    link
    fedilink
    arrow-up
    16
    ·
    edit-2
    2 months ago
    *char // I heard it from a friend
    **char //who heard it from a friend
    ***char // who heard it from another
    "You were messing around"
    
  • RonSijm@programming.dev
    link
    fedilink
    arrow-up
    7
    ·
    2 months ago

    Me: building a fluent interface framework…
    I already support a WrapperOf<T, T, T, T>
    User: Can I have a WrapperOf<T, T, T, T, T> because I’m doing something weird?
    Me: *sigh* god-damnit. You’re right but I still hate it.

  • jvw@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    3
    ·
    2 months ago

    Isn’t that like, how you declare different dimensionally sized arrays? If you don’t care about memory integrity?

    It’s been literally decades since I had to deal with code like that, so I may have jumped my stack.

    • calcopiritus@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      2 months ago

      If you do it with fixed-size arrays you can accomplish multi-dimension with just int*. Lots of pointer arithmetic needed though. Probably still faster than n levels of indirection.

    • renormalizer@feddit.org
      link
      fedilink
      Deutsch
      arrow-up
      4
      ·
      edit-2
      2 months ago

      I’ve been a four-star programmer a few times. Imagine a blocked symmetric matrix where the rows and columns are indexed by triples (u,v,w). The entries are zero whenever u != u’ or v != v’, and because of symmetry you only store entries with w <= w’. But the range of v depends on the value of u and the range of w on the value of v. So you do

      double ****mat = calloc (UMAX, sizeof(*mat));
      for (int u = 0; u < UMAX; ++u) {
        mat[u] = calloc (u + 1, sizeof(**mat));
        for (int v = 0; v <= u; ++v) {
          mat[u][v] = calloc (v + 1, sizeof(***mat));
          for (int w = 0; w <= v; ++w) {
            mat[u][v][w] = calloc (w + 1, sizeof(****mat));
            for (int ww = 0; ww <= w; ++ww)
              mat[u][v][w][ww] = some_function (u, v, w, ww);
          }
        }
      }
      

      and weep a little. In reality, this gets a bit optimized by allocating a single chunk of memory and carving that up into the pointer and data arrays, so everything is reasonably close together in memory.