this post was submitted on 05 Aug 2024
261 points (94.2% liked)

Programmer Humor

19187 readers
1305 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
261
Do you know who can help? (programming.dev)
submitted 1 month ago* (last edited 1 month ago) by [email protected] to c/[email protected]
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 1 month ago (1 children)

Is there a code example of this?

[–] [email protected] 5 points 1 month ago* (last edited 1 month ago) (2 children)

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.

[–] Agent641 4 points 1 month ago
[–] [email protected] 3 points 1 month ago

My brain hurts