#undef

Ughhh, autotools....

Not naming the project here.. Why would you assume that malloc and realloc are both broken just because you're cross compiling? Are you just being lazy? Even worse, don't '#undef malloc' and replace it with your own *broken* version.

Better yet, just don't even use autotools at all.

ity [unit X-69]ity@estradiol.city
2025-06-10
/*
* The sys_call_table[] is no longer used for system calls, but
* kernel/trace/trace_syscalls.c still wants to know the system
* call address.
*/
#define __SYSCALL(nr, sym) __x64_##sym,
const sys_call_ptr_t sys_call_table[] = {
#include <asm/syscalls_64.h>
};
#undef __SYSCALL

#define __SYSCALL(nr, sym) case nr: return __x64_##sym(regs);
long x64_sys_call(const struct pt_regs *regs, unsigned int nr)
{
switch (nr) {
#include <asm/syscalls_64.h>
default: return __x64_sys_ni_syscall(regs);
}
}

:neobot_glare_sob:

lizzy :bi_heart: :cuwu:lizzy@social.vlhl.dev
2025-05-17

silly little thing i made to debug that heisenbug

collecting all the things that i want to log and printing them after the fact, this avoids the overhead of printing immediately that seeming skewed the timing enough to make the bug disappear

there is one logger for every relevant thread, because synchronizing the logging would have also skewed the result obviously

struct microlog_entry
{
    LONGLONG perf;
    const char *text;
};

#define MICROLOGGER_CAP 100

struct micrologger
{
    size_t pos;
    size_t read_pos;
    struct microlog_entry entries[MICROLOGGER_CAP];
};

#define microlog(l, text) if (l.pos < MICROLOGGER_CAP) { \
        LARGE_INTEGER perf; \
        QueryPerformanceCounter(&perf); \
        l.entries[l.pos++] = (struct microlog_entry) { perf.QuadPart, text }; \
    }

static struct micrologger l_grabber_events;
static struct micrologger l_grabber_samples;
static struct micrologger l_main;

void microlog_flush()
{
#define NUM_MICROLOGGERS 3
    struct micrologger *loggers[NUM_MICROLOGGERS] = { &l_grabber_events, &l_grabber_samples, &l_main };

    for (;;) {
        struct micrologger *least = NULL;

        for (size_t i = 0; i < NUM_MICROLOGGERS; i++) {
            if (loggers[i]->read_pos == loggers[i]->pos)
                continue;
            if (!least || loggers[i]->entries[loggers[i]->read_pos].perf < least->entries[least->read_pos].perf)
                least = loggers[i];
        }

        if (!least)
            break;

        printf("%s\n", least->entries[least->read_pos].text);
        least->read_pos++;
    }
#undef NUM_MICROLOGGERS
}
2025-05-08
@sun @Jdogg247 @DailyStormerDigest

#undef BEAUTY
#define BEAUTY "okay buddy"
Jevin Swevaljevinskie
2025-04-11

How to politely use assert in a header (gcc/clang/msvc/what else?):

push_macro("NDEBUG")
NDEBUG
<assert.h>
// your asserts should properly assert
pop_macro("NDEBUG")
// nobody has 2 know

Your vendor’s assert.h should be able to be included multiple times with NDEBUG defined or not.

the freebsd gamermothcompute@vixen.zone
2025-03-03
async sjolsensjolsen@tech.lgbt
2025-02-26

@kirakira did you know that you can define structured data in the c preprocessor using church encoding?

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#define USERS(_user) \
_user("sjolsen", "tech.lgbt"), \
_user("kirakira", "furry.engineer"), \
_user("Gargron", "mastodon.social")

#define handles_user(_name, _instance) "@" _name "@" _instance

static const char *const handles[] = {
USERS(handles_user)
};

#undef handles_user

#define ARRAY_SIZE(_a) (sizeof(_a) / sizeof(_a[0]))

int main() {
for (size_t i = 0; i < ARRAY_SIZE(handles); ++i) {
puts(handles[i]);
}

return EXIT_SUCCESS;
}
2025-02-05

@ipg

#undef HAS_GAMES
2025-01-07

The Fourth Hard Problem in Computer Science:

Whether to use

#define FOO 0

or

/* #undef FOO */

or

#undef FOO

or even

/* #define FOO */

for things that aren't present/enabled/turned on in a config.h. FOO can start with HAVE_ or not.

Jari Komppa 🇫🇮 (has moved)sol_hsa@peoplemaking.games
2024-12-12

@pythno I think I remember having to do a kludge to work around that at some point.

I think the min/max are macros in windows.h, so #undef should do the trick.

2024-10-04

@icculus I love SDL and have been using it for more than a decade, but the way they treat `main` always bothered me (`#define main SDL_main` is already obnoxious, and the actual main being implemented in a standalone shared lib is extra spicy). I always just did `#undef main` and took control from SDL on this.

Now they're making this thing even more integral and this makes me sad :(

(yes you can at least disable it with a special macro, but this being the default really bothers me)

DJ月経少年野崎くんA.K.A杜仲茶またの名を立花いづみtochu_cha@mstdn.jp
2024-09-17

gosh> (print "a")
a
#undef

なんでシンボルかと思っても文字列だぞ。気を付けろ!(俺がな)

IB Teguh TMteguhteja
2024-09-17

Discover how conditional compilation directives can enhance your C programming skills. Learn to use , , , , , , and to create more flexible and efficient code. Unlock the power of the C preprocessor!

teguhteja.id/conditional-compi

2024-09-13

what was in the air in 1997 bro
/* define the boolean values in a general and
* portable way.
*/
#undef TRUE
#define TRUE (0 || !(0))
#undef FALSE
#define FALSE (!(TRUE))
/* typedef enum { false = FALSE, true = TRUE } bool; */

/* some other names for true and false */
#define YES TRUE
#define NO FALSE

#define GOOD TRUE
#define WRONG FALSE

#undef OK
#define OK TRUE
#define BAD FALSE

#define SOME TRUE
#define NONE FALSE

mccmcc
2024-07-22

@fluor I've seen people do complex repeated-include metaprogramming with the C preprocessor for sure (it helps to know about , and ##) but also leaning on the C preprocessor this way can get you in some very hard to debug spots very fast.

2024-05-30

Recursive inclusion is possible in C, and more surprisingly it even makes sense in some cases. In fact it provides an easy way to do code unrolling of small code snippets:

#if !defined(DO_I) || (DO_I < DO_BOUND)# include "do-incr.c"DO_BODY# include __FILE__#endif#undef DO_I

Here this uses two macros that have to be defined beforehand, DO_BOUND and DO_BODY, and one macro DO_I for a hexadecimal loop counter that is maintained by the include file "do-incr.c". If we hold the above recursive code in some file "doit.c" (plus some extras, see below) we can use this as simply as in

#define DO_BODY [DO_I] = DO_I,#define DO_BOUND 0x17unsigned array[] = {# include "doit.c"};#undef DO_BODY#undef DO_BOUND

do generate the intialization of an array,

unsigned array[] = {[0x0000] = 0x0000,[0x0001] = 0x0001,...[0x0016] = 0x0016,[0x0017] = 0x0017,};

or with an additional macro DO_NAME (DO_I without a hex prefix) as

#define ENAME_(X) enum_ ## X#define ENAME(X) ENAME_(X)#define DO_BODY ENAME(DO_NAME) = DO_I,#define DO_BOUND 197enum {# include "doit.c"};#undef DO_BODY#undef DO_BOUND

for the declaration of an enumeration type

enum fun {enum_0000 = 0x0000,enum_0001 = 0x0001,...enum_00C4 = 0x00C4,enum_00C5 = 0x00C5,};

Here the given limit of 197 is in fact a limit that is imposed by gcc for which I was testing this. They restrict the depth of inclusion to 200, unless you raise that limit with the command line option -fmax-include-depth.

Note also, that the recursive line #include __FILE__ uses a macro to specify the file name because #include lines are indeed evaluated by the preprocessor if necessary.

Recursion is only reasonable if we have a stop condition, so to handle this the include file "do-incr.c" is crucial. Since in standard C we have no way to evaluate the line of a #define while processing it, we have to ensure that we can change the value of DO_I. That file looks something like

#ifndef DO_I# undef  DO_I0# define DO_I0 0# undef  DO_I1# define DO_I1 0# undef  DO_I2# define DO_I2 0# undef  DO_I3# define DO_I3 0# define DO_I DO_HEX(DO_NAME)#elif DO_HEX(DO_I0) == 0# undef DO_I0# define DO_I0 1#elif DO_HEX(DO_I0) == 1# undef DO_I0# define DO_I0 2...#elif DO_HEX(DO_I0) == 0xF# undef DO_I0# define DO_I0 0# include "do-incr1.c"#endif

As you may have guessed, this uses macros DO_I0, DO_I1, DO_I2, and DO_I3 as hexdigits of a 16 bit number, and includes another file "do-incr1.c" if the digit DO_I0 overflows.

I hope that if you are interested in this technique, you will be able to join the dots in the above code. To be complete, here are the macros that join the digits to make a hexnumber (DO_HEX) and to make a name component (DO_NAME):

#ifndef DO_HEX# define DO_HEX_(X) 0x ## X# define DO_HEX(X) DO_HEX_(X)# define DO_NAME_(A, B, C, D) A ## B ## C ## D# define DO_NAME_IIII(A, B, C, D) DO_NAME_(D, C, B, A)# define DO_NAME DO_NAME_IIII(DO_I0, DO_I1, DO_I2, DO_I3)#endif

https://gustedt.wordpress.com/2024/05/30/include-__file__/

#define #elif #endif #undef

2024-05-19

uaa@emeraude:~/duo-buildroot-sdk-Duo-V1.1.0$ find .|grep cv180x-asic
./u-boot-2021.10/include/configs/cv180x-asic.h
uaa@emeraude:~/duo-buildroot-sdk-Duo-V1.1.0$

uaa@emeraude:~/LicheeRV-Nano-Build$ find .|grep cv180x-asic
uaa@emeraude:~/LicheeRV-Nano-Build$

#undef CONFIG_ENV_なんたらしてるcv180x-asic.hが無いなら、もしかしてEFI bootloaderがすんなり動いたりするんだろうか。とはいえ、SG2002の眷属をこれ以上増やせる余裕は無いしLicheeRV-NanoのバイナリをMilk-V Duoに食わせるくらいは…してもいいのかなあ。

2024-04-29

cv180x-palladium.h:#undef CONFIG_ENV_OFFSET
cv180x-palladium.h:#undef CONFIG_ENV_OFFSET_REDUND
cv180x-palladium.h:#undef CONFIG_ENV_SIZE
cv180x-palladium.h:#undef CONFIG_ENV_IS_IN_SPI_FLASH
cv180x-palladium.h:#undef CONFIG_ENV_IS_IN_MMC
cv180x-palladium.h:#undef CONFIG_ENV_IS_IN_NAND
cv180x-palladium.h:#undef CONFIG_ENV_SECT_SIZE
cv180x-palladium.h:#undef CONFIG_BOOTCOMMAND

2024-04-29

cv180x-fpga.h:#undef CONFIG_ENV_OFFSET
cv180x-fpga.h:#undef CONFIG_ENV_OFFSET_REDUND
cv180x-fpga.h:#undef CONFIG_ENV_SIZE
cv180x-fpga.h:#undef CONFIG_ENV_IS_IN_SPI_FLASH
cv180x-fpga.h:#undef CONFIG_ENV_IS_IN_MMC
cv180x-fpga.h:#undef CONFIG_ENV_IS_IN_NAND
cv180x-fpga.h:#undef CONFIG_ENV_SECT_SIZE
cv180x-fpga.h:#undef CONFIG_BOOTCOMMAND

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst