Email or username:

Password:

Forgot your password?
lawless polymorph

C library functions are always like: "SYNOPSIS. This function converts foos into bars depending on the user locale. ARGUMENTS. src and dest pointers must be distinct; it is undefined behavior if they are not QPU-aligned. RETURN VALUE. Returns the number of foos converted. A zero value indicates failure, or that zero foos were converted. A negative value indicates that the final foo was only partially converted (function got tired). Check this global variable to find out why."

24 comments
Boarders

@typeswitch it sounds bad BUT you can target this code to not work on multiple platforms in multiple distinct ways

mos_8502 :verified:

@typeswitch The exact type of C I have spent 20+ years intentionally avoiding writing.

mos_8502 :verified:

@typeswitch Your criticism is dead on accurate. I’ve made one of my life goals to write C like someone who actually wants a human being to comprehend it.

I design opaque types that get passed around as pointers with no direct access to member variables, only through a tailored API. I use proper structural return types (result/status tuple structures). I use GC or manual retain release with deinit functions instead of malloc/free wrappers to manage lifetimes. I strive to be an example of what C can be if effort is applied.

@typeswitch Your criticism is dead on accurate. I’ve made one of my life goals to write C like someone who actually wants a human being to comprehend it.

I design opaque types that get passed around as pointers with no direct access to member variables, only through a tailored API. I use proper structural return types (result/status tuple structures). I use GC or manual retain release with deinit functions instead of malloc/free wrappers to manage lifetimes. I strive to be an example of what C can...

Vertigo #$FF

@mos_8502 @typeswitch All that being said, I still like the man-page formatting for reference documentation. You can have the most pristinely architected C code in the world, but if I can't wrap my head around the over-arching architecture and/or how pieces fit together, the first place I will go to will be the API documentation for help.

bkim

@mos_8502 @typeswitch I've never programmed in C professionally, but love me some good software engineering. What do you mean by "manual retain release" and "deinit" functions? Do you have any example I can learn from?

niconiconi

@typeswitch@gamedev.lgbt function got tired? more like "function got distracted by other things" according to how Unix syscalls were designed

Billy O'Neal

@typeswitch @thephd You forgot "flags is a bit mask of 22 bits some of which can be used together and some of which can not which make this function do totally different things"

Sean Murthy

@malwareminigun @typeswitch @thephd The beloved `dwFlags` parameter. These two gems on that page, are just 😗:

The function performs more quickly when none of these flags is set.

If all three values are not provided, some results will be missing.

Pär Björklund

@malwareminigun @smurthys @typeswitch @thephd the win32 is pretty great, the size of it all means it contains just about every API design issue one can think of, now, in hindsight 😀

I do actually like it overall though

Billy O'Neal

@Paxxi I didn't intend to rip on Win32 specifically here; lots of C APIs are horrible. And I'll take a lot of these to one fork(). An API that looks basic but has far-reaching implications, makes accurate memory use tracking impossible, and generally creates cross cutting costs against the whole system. Whereas these examples are contained to only their immediate callers.

Pär Björklund

@malwareminigun I totally agree, and as I said I generally like the win32 api 😀

Dominic

@malwareminigun @typeswitch @thephd a personal favorite is "given this flag, the type of parameter 3 changes from T* to T**"

🏳️‍⚧️ LinuxEnjoyer 🐧

@typeswitch@gamedev.lgbt also the flags argument that is explained in the man page for a completely different function :')

Ollie

@typeswitch Actual comment from a C library I'm working on.

I'm not a C programmer usually, but it seems I've fallen into the same trap.

EDIT: Alt-text

A comment from a C library that says:

(Almost) Everything from here on will be composed with the raw float memory We use a uin32_t to represent the raw float data because it is a container of the same size. It also supports all the operations we want to do from here on.

C/C++ implicit conversion will turn it into a value-preserving integer, but not a data-preserving integer. For instance, the implicit conversion of 12.5 to an integer will become 13, which preserves value (as much as possible), but the memory layout will be entirely different.

All explicit conversions to raw memory then to another type are to leave memory layout completely unaltered, which allows us to do our magic.
Denis Drakhnia
@typeswitch

C library functions are always like: "SYNOPSIS. This function converts :blobCat: into :blobfox: depending on the user locale. ARGUMENTS. src and dest pointers must be distinct; it is undefined behavior if they are not QPU-aligned. RETURN VALUE. Returns the number of :blobCat: converted. A zero value indicates failure, or that zero :blobCat: were converted. A negative value indicates that the final :blobcatfox: was only partially converted (function got tired). Check this global variable to find out why."

Much better.

:02_laugh: :02_laugh: :02_laugh:
@typeswitch

C library functions are always like: "SYNOPSIS. This function converts :blobCat: into :blobfox: depending on the user locale. ARGUMENTS. src and dest pointers must be distinct; it is undefined behavior if they are not QPU-aligned. RETURN VALUE. Returns the number of :blobCat: converted. A zero value indicates failure, or that zero :blobCat: were converted. A negative value indicates that...
Trif

@typeswitch@gamedev.lgbt I build up speed for 12 hours to align my pointers

Phel

@typeswitch Honestly I rather have this than some doxygen badly rendering on mobile, saying things like "Factory for ElementManager" for classes named "ElementManagerFactory" as documentation to figure out why my application segfaults again

Astrid (Certified Server Maid)
@typeswitch ERRORS. EUNRDBL can occur if any of the following five conditions occur:
Go Up