logoalt Hacker News

Panzerschrek • today at 3:05 PM • 4 replies • view on HN

I don't understand people reinventing macro-based hacks in C to achieve what was achieved in other languages many years ago. Why not using C++, for example? It's available almost everywhere, introducing its usage in an existing C codebase is pretty simple. Sure, C++ has its own downsides, but is it better to create mess with macros in C rather then using exiting language facilities and standard library containers provided by C++?


Replies

uecker • today at 3:37 PM

Having used C++ a lot in the past, I think the mess in C++ is way worse. I also contribute to projects that introduce C++ into a C code base, and I really wish they hadn't done this.

Although there are C features I like that I would need to remove before introducing C++ to a codebase, so this may not always be so simple.

➕ show 1 reply
rwbt • today at 3:30 PM

I'd rather not migrate my C codebase to C++ just to use an array container. Very hard to consistently limit the codebase to a strict subset of C++.

➕ show 1 reply
Joker_vD • today at 3:11 PM

For one reason, it is because C++ runtime (and its standard library) is a whole own can of worms which most people would rather not touch if they can afford to. Which they mostly can.

> Sure, C++ has its own downsides

"Sure, getting your eyes gouged out has its downsides, but is it better to read that awful mess of macros in C instead?" The answer most people would give to this question may surprise you.

➕ show 1 reply
0xbadcafebee • today at 4:15 PM

If you want better tires on your car, why not just get a different car?