Why Use C++ Instead of C?
Why does everyone keep telling me to use c++? (self.programminghorror) submitted 2 hours ago by ZERIC020020 My task was to create a function in C that would take an integer, find the right-most 0, flip it to a 1, and flip all the 1's to the right of it to 0's. I don't understand why, but everyone tells me to just use c++ instead? Strange. uint32_t func(uint32_t c) { uint32_t i = 1; while (i != 0) { // Searches for the right-most 0 if ((c & i) == 0) { // Tests if the bit is a zero break; } i <<= 1; }; if (i != 0) { c |= i; // Flips the right-most 0 to a 1 } else { c = ~c; // If no zeros were found, then it was probably hidden in the carry bit, flip all 1's to the } i >>= 1; // Start at the 1 next to the right-most 0 while (i != 0) { // flip all 1's to the right of it to 0's c &= ~i; i >>= 1; }; return c; } Why are people so adamant that I use c++ instead of C?
Скриншот вопроса программиста о функции на C, которая манипулирует битами целого числа. Автор приводит чрезмерно сложную реализацию, а затем удивляется, почему все советуют ему использовать C++; шутка в том, что код выглядит как настоящий programming horror и сам объясняет рекомендацию.
programming forum screenshot / скриншот форума программистовcode editor / редактор кодаC source code / исходный код на CC++ reference / упоминание C++monospaced text / моноширинный текстinteger variable / целочисленная переменнаяbinary bit operations / побитовые операцииscroll bar / полоса прокруткиwhite webpage / белая веб-страница
- @pokupkabitka / 33379 2024-01-03
- @gentoomemes / 8479 2024-01-03
- @dev_meme / 7432 2025-11-18
- Type
- image
- Size
- 800×502 · 60.7 KiB
- Mood
- саркастичный, абсурдный
- Language
- en
- Added