News for hackers. Stuff that matters.
Re:Dale – A Lisp-flavoured C by kazinator on Monday April 10, 2017 @11:16PM (#14084561)
> The abuse of the preprocessor for checking pointer size is definitely poor practice.

[Non-moving-target reference with commit hash: http://www.kylheku.com/cgit/txr/tree/rand.c?id=6ca6be767f8ac... ]

The problem with your statement is that it isn't true.

Selecting code alternatives using #ifdef is one of the benign uses of the C preprocessing feature, exemplifying "use it like this" in contrast with "bad" uses. In many a coding guide you can it recommended to use the preprocessor to do a little #ifdef here and there, while avoiding crazy macros. (Of course, code can turn into a hairball of nested #ifdefs, which everyone rightfully hates, but this sort of use is not characterized with the word abuse. It is just use.)

We could split the function into two copies for those alternatives, put them into separate files and then have something slick in the Makefile to pick the correct file (not the GNU Make ifeq syntax, of course; that would be ironic).

However, those two functions would then contain lots of repeated code also. If something has to change, two identical parts in similar functions have to be updated.

Okay so then we could refactor the function so that all the common things are in a generic part, and then the switched pieces are in a helper inline function (included from one of two different files, etc).

It's not clear that it would improve things in that particular case.

I really have no idea what, if anything, would be worth doing, and that could be due to my mental limitations. If someone sends me a plan about how to refactor that code in a good way (just an outline with bullet points in plain language, no code) I will seriously consider it, and possibly do the work.

There are no comments on this comment yet.