Email or username:

Password:

Forgot your password?
Lennart Poettering

PSA for C devs: if your library exposes a function that takes a pointer, and you add a "const" to that pointer later on, then yes, that's an API break. Why? Because the prototype of the function changed enough so that anyone taking a pointer of your function won't be able to assign it to the variable they intend to store it in. Yes, C API compat is hard. (libbpf, I am looking at you ๐Ÿ‘€๐Ÿ‘€๐Ÿ‘€, btw)

7 comments
Bebna

@pid_eins
is there a good guide how to do c lib APIs?

Julian Andres Klode ๐Ÿณ๏ธโ€๐ŸŒˆ

@pid_eins I see it like glibc: API compatibility matters less than ABI compatibility.

But also you can hack that if you need to, by

#ifdef FOO_COMPILING_FOO
#define internal_const const
#else
#define internal_const
#endif

And using that in the header. And yes, that's what I might resort too.

Marc-Antoine Perennou

@pid_eins is it considered less critical if itโ€™s provided with a typedef of the fn signature and the typedef gets updated too?

Lennart Poettering

@Keruspe nah, it's not that likely people would even use that typedef. I mean, we certainly didn't when I ran into this mess with libbpf (github.com/systemd/systemd/pul)

Toke Hรธiland-Jรธrgensen
@pid_eins Well, libbpf has always had an... interesting... approach to backwards compatibility. It's supposed to be better going forward, now that it's reached v1.0. I guess time will tell...
Simon Ser

@pid_eins I've just done that with the Pixman API, and honestly, I don't care. Use an explicit cast if you do.

Go Up