@benbrown Now that would be my epitaph for my tombstone, coded in C:

// [my name here as an author]
// [my birthdate] - [my deathdate]

#include <stdio.h>

main() {
printf("Goodbye world!\n");
}

@aeva @hipsterelectron i never noticed this before, but: in C++, the only difference between "unspecified" and "implementation-defined" is a requirement to provide documentation:

https://eel.is/c++draft/defns.impl.defined
https://eel.is/c++draft/defns.unspecified

(so e.g. where the standard says that the details of searching for a header file for an ` #include` are implementation-defined, that means the compiler vendor needs to document its rules for header searching (otherwise it's not a conforming implementation).)

@aeva @hipsterelectron i never noticed this before, but: in C++, the only difference between "unspecified" and "implementation-defined" is a requirement to provide documentation:

https://eel.is/c++draft/defns.impl.defined
https://eel.is/c++draft/defns.unspecified

(so e.g. where the standard says that the details of searching for a header file for an ` #include` are implementation-defined, that means the compiler vendor needs to document its rules for header searching (otherwise it's not a conforming implementation).)

Linux kernel quiz: Why is this program so slow and takes around 50ms to run?
What line do you have to add to make it run in 3ms instead without interfering with what this program does?

user@debian12:/test$ cat > slow.c
#include
#include
#include
#include

static void open_sockets(void) {
for (int i=0; i<256; i++) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1)
err(1, "socket");
}
}

static void *thread_fn(void *dummy) {
open_sockets();
return NULL;
}

int main(void) {
pthread_t thread;
if (pthread_create(&thread, NULL, thread_fn, NULL))
errx(1, "pthread_create");
open_sockets();
if (pthread_join(thread, NULL))
errx(1, "pthread_join");
return 0;
}
user@debian12:/test$ gcc -O2 -o slow slow.c -Wall
user@debian12:
/test$ time ./slow

real 0m0.041s
user 0m0.003s
sys 0m0.000s
user@debian12:/test$ time ./slow

real 0m0.053s
user 0m0.003s
sys 0m0.000s
user@debian12:
/test$

Linux kernel quiz: Why is this program so slow and takes around 50ms to run?
What line do you have to add to make it run in 3ms instead without interfering with what this program does?

user@debian12:/test$ cat > slow.c
#include
#include
#include
#include

static void open_sockets(void) {
for (int i=0; i<256; i++) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == -1)
err(1, "socket");
}
}

static void *thread_fn(void *dummy) {
open_sockets();
return NULL;
}

int main(void) {
pthread_t thread;
if (pthread_create(&thread, NULL, thread_fn, NULL))
errx(1, "pthread_create");
open_sockets();
if (pthread_join(thread, NULL))
errx(1, "pthread_join");
return 0;
}
user@debian12:/test$ gcc -O2 -o slow slow.c -Wall
user@debian12:
/test$ time ./slow

real 0m0.041s
user 0m0.003s
sys 0m0.000s
user@debian12:/test$ time ./slow

real 0m0.053s
user 0m0.003s
sys 0m0.000s
user@debian12:
/test$

Dear C++ people: how do you actually fucking do this? It seems bad enough that I need to have two overloads just to allow for the "no args" version.

But that template overload fails at link time because of an undefined symbol???

UPDATE: It’s because I needed to define it in the header file itself, not just declare it

@zkat
```cpp
#include <format>
#include <print>

template <typename... Args>
void info(std::format_string<Args...> fmt, Args&&... args) {
auto res = std::format(fmt, std::forward<Args&&>(args)...);
std::println("{}", res);
}

int main() {
info("{}", 42);
info("moi");
}
```

Seems to work in compiler explorer. Typos might be present, writing this on phone. Did you need something else?

Failing on link time might happen if you have template in a source code file not visible to an another translation unit (which is why we write template code into headers, or modules if we're in the future).

@lauren Typical. Still not the craziest thing he’s uttered.

Did not have cheering for Murdoch on my 2025 bingo card. #include nathanfillion.gif

alcinnz
BjarniBjarniBjarni  🙊 🇮🇸 🍏
alcinnz and 1 other boosted

This was fun - missing.c:

#include
#include

void die(int err, char *msg) {
err? fprintf(stderr, "%s\n", msg), exit(1): 0;
}

int main(int argc, char *argv[]) {
int n, answer = 1, val;

die(argc != 2 || (n = atoi(argv[1])) < 2, "Usage: missing n");
for (; n > 1; n--) {
die(scanf("%d", &val) != 1, "Error reading input");
answer ^= val ^ n;
}
printf("%d\n", answer);
}

This was fun - missing.c:

#include
#include

void die(int err, char *msg) {
err? fprintf(stderr, "%s\n", msg), exit(1): 0;
}

int main(int argc, char *argv[]) {
int n, answer = 1, val;

die(argc != 2 || (n = atoi(argv[1])) < 2, "Usage: missing n");
for (; n > 1; n--) {
die(scanf("%d", &val) != 1, "Error reading input");
answer ^= val ^ n;
}
printf("%d\n", answer);
}