#ifdef

Wild Eyed Boy From FreecloudWildEyedBoyFromFreecloud@masto.ai
2025-05-07

@tubetime I miss #ifdef... What a great way to knock out a 💩 ton of code.

Larry (Mr.Optimization)fast_code_r_us@floss.social
2025-05-07

Small success today - my Cinepak player can now auto-detect AVI and Quicktime (mov) files and play videos from either. Still some things to fix, but it's coming along. The lite/low-memory version is enabled with an #ifdef. I'm thinking of making this a runtime choice, but it creates some challenges.

NetBSD Source Changesnetbsdsrc@mstdn.social
2025-05-06
Luke T. Shumakerlukeshu@social.coop
2025-05-05

Oh hey the kernel's copy of l.s has (behind `#ifdef BOOT`, which is never defined) that "same" code, but didn't forget to set GS and FS.

#Plan9 1e had a lot of bad code-duplication that should have been code-reuse. Actually, later editions are still pretty bad about this too.

#RetroComputing #ReverseEngineering

@foone

Agreed, but there's also a lot of `#ifdef __GNU_SOURCE` and such in the open-source world, too.

2025-04-29

(Possibly relevant to @b0rk 's interests)

So I hit a flag in diff, --unchanged-group-format. It does not show up in the manpage. It does not show up in --help. You can search both those channels for that string and you will not find it.

You know where it shows up first? If you Google it, you'll get an example in gnu.org/software/diffutils/man.

So why doesn't it show up in the manpage? Well, it does! If you read the entire manpage. With your eyes.

  -D, --ifdef=NAME                output merged file with '#ifdef NAME' diffs                                                                                                                                                                                                                                                                                                              
--GTYPE-group-format=GFMT format GTYPE input groups with GFMT
--line-format=LFMT format all input lines with LFMT
--LTYPE-line-format=LFMT format LTYPE input lines with LFMT
These format options provide fine-grained control over the output
of diff, generalizing -D/--ifdef.
LTYPE is 'old', 'new', or 'unchanged'. GTYPE is LTYPE or 'changed'.

"What do you mean it isn't documented? Of course it's documented. You did read every line and do some template-substitution in your brain, didn't you?"

This isn't advocating for not reading the manpage. If you really want to understand how the tool works, you read the whole manpage. And probably the source code. 😉

... but I don't want to understand how the tool works. I want to diff two files and not have the lines that are the same get emitted.

And I think a lot of application- and solution-generating computer people, most of the time, in most of their careers, are operating on that level of depth. Problems come in too fast and with too much variety. You absolutely go deep on some things. There is no time to go deep on everything.

So how do we address this (other than throw up our hands and say "Relying on Google's fuzzy search of the whole Internet and vibe-coding LLMs is the future actually")? I don't have magic bullets, but a "fuzzy search" mode in something like less that could take an input like --unchanged-group-format and twig that it if there's no exact match, it might be related to --GTYPE-group-format would be nice.

Maybe I should mock that up in emacs. Actually, I bet someone already put it in emacs. ;)

#emacs #manpage #less

2025-04-26
2025-04-13

うーん。FreeDV-GUI、sioclientが無いことを想定していない作りになっているのでsioclient抜きのビルドをしたいとなるとかなり大掛かりな修正が必要になりそう。

#ifdef~#endifで切るよりは、ダミーに置き換えたコードを作った方が良いのかも)

2025-04-11
static const struct memdev {
const char *name;
const struct file_operations *fops;
fmode_t fmode;
umode_t mode;
} devlist[] = {
#ifdef CONFIG_DEVMEM
[DEVMEM_MINOR] = { "mem", &mem_fops, 0, 0 },
#endif
[3] = { "null", &null_fops, FMODE_NOWAIT, 0666 },
#ifdef CONFIG_DEVPORT
[4] = { "port", &port_fops, 0, 0 },
#endif
[5] = { "zero", &zero_fops, FMODE_NOWAIT, 0666 },
[7] = { "full", &full_fops, 0, 0666 },
[8] = { "random", &random_fops, FMODE_NOWAIT, 0666 },
[9] = { "urandom", &urandom_fops, FMODE_NOWAIT, 0666 },
#ifdef CONFIG_PRINTK
[11] = { "kmsg", &kmsg_fops, 0, 0644 },
#endif
};
2025-04-10
#ifdef CONFIG_PROC_FS

void chrdev_show(struct seq_file *f, off_t offset)
{
struct char_device_struct *cd;

mutex_lock(&chrdevs_lock);
for (cd = chrdevs[major_to_index(offset)]; cd; cd = cd->next) {
if (cd->major == offset)
seq_printf(f, "%3d %s\n", cd->major, cd->name);
}
mutex_unlock(&chrdevs_lock);
}

#endif /* CONFIG_PROC_FS */

fs/char_dev.c

This is evil. Evil. Just evil. Why Linus oh why why why why why did you merge this code 19 years ago

Björkus "No time_t to Die" Dorkusthephd@pony.social
2025-04-06

@siguza @fay59 Yes. If you're not just going to infinitely backport this, you need #ifdef perhaps combined with __asm__("...") . The standard version of that is Transparent Aliases ( thephd.dev/_vendor/future_cxx/ ) which is being worked on for C2y.

But you don't have to use __STDC_VERSION__ specifically: rather than ask the compiler, you ask the header using the C23-introduced __STDC_STDIO_H_VERSION__ header macro. The library controls that macro, so if the library says it's at <stdio.h> for C2y, it had better implement a C2y formatter like it's promising. That's how the compiler can check if it REALLY wanted to. Or, both versions get baked into the e.g. the format attribute and it's up to the library vendor to select which version they care about.

There are many ways to skin this cat. Implementations have been doing this since time immemorial (see _DARWIN_ALIAS(...) and other shenanigans).

wirepairwirepair
2025-04-05

fucking hell winspool.h:

UNICODE
AddJob AddJobW

AddJob AddJobA
// !UNICODE

Jolt defines a class method called...
virtual void AddJob(const JobHandle &inJob) override;

guess some ordering got re-arranged and now my shit is conflicting

2025-04-03

@mikeymikey @kickingvegas @siracusa is that an #ifdef in a shell script? What?

2025-04-02

In one file in the CnC Red Alert source, there's an #ifdef TIBERIAN_SUN and that had me really excited for a moment.

Michał Fitamichalfita
2025-04-02

@imperio I knew so many people using FreeBSD and no one really complaint before. I personally don't use it (have it on my old NAS), but reasons are historical/technical.

I think BSD operates in a old model of `autoconf` probing API features and adjusting by tons of ``, what obviously doesn't play well with .

2025-04-01

Вот почему Сишные директивы надо писать с начала строки по многим кодстайлам.

Как по мне любой if приятнее читать если его тело оттабулированно и его можно без проблем воспринять визуально, не вдумываясь сознательно где начало, а где конец.
Даже если это #ifdef, кажется что так удобнее.

Хотя ясен аргумент, что это выделяет данные блоки кода и сразу форсит обратить внимание на то что ЭТИМ занимается препроцессор.

Может такие правила кодстайла это рудименты во времена без подсветки синтаксиса?

#C #программирование

2025-03-23

@jackwilliambell The only time I use a separate directory for includes is if I have an include file that's specific to a certain platform. Sometimes, instead of using #ifdef for each platform in a header file, I create an include file with the same name for each platform and put them in their own directories. It depends on how platform specific the code is and what's more readable for the specific case.

phase separation anxiolyteamsomniac@mastodon.mit.edu
2025-03-18

@atax1a #ifdef #include these are decent tags! love the vibe

phase separation anxiolyteamsomniac@mastodon.mit.edu
2025-03-18

I am now following the hashtags #ifdef and #include

mx alex tax1a - 2020 (5)atax1a@infosec.exchange
2025-03-18

@amsomniac c programmers posting here know about the #ifdef hashtag

Client Info

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