Telegram Group & Telegram Channel
📚 Загадочная библиотека setjmp.h — неочевидный инструмент для управления потоком выполнения


Библиотека setjmp.h предоставляет два необычных макроса:

setjmp — сохраняет текущее состояние программы (регистры, стек) в буфер jmp_buf

longjmp — «откатывает» выполнение к сохранённому состоянию, как прыжок во времени



#include <stdio.h>
#include <setjmp.h>

jmp_buf jump_buffer;

void risky_function() {
printf("Готовимся к прыжку...\n");
longjmp(jump_buffer, 42); // Прыжок обратно в setjmp!
}

int main() {
int ret = setjmp(jump_buffer);
if (ret == 0) {
printf("Первая инициализация...\n");
risky_function();
} else {
printf("Вернулись с кодом: %d\n", ret); // Выведет 42!
}
return 0;
}


⚠️ Осторожно!

• Не заменяет исключения — нет вызова деструкторов (как в C++)
• Опасность утечек — если между setjmp и longjmp выделялась память, она не освободится
• Портит стек — может сломать логику функций

🛠 Где может пригодиться?

• Обработка критических ошибок (а-ля «аварийный выход»)
• Код для встраиваемых систем, где нужно быстро восстановить состояние
• Нестандартные хаки (но лучше так не делать 😈)

Библиотека C/C++ разработчика



tg-me.com/cpp_interview_lib/861
Create:
Last Update:

📚 Загадочная библиотека setjmp.h — неочевидный инструмент для управления потоком выполнения


Библиотека setjmp.h предоставляет два необычных макроса:

setjmp — сохраняет текущее состояние программы (регистры, стек) в буфер jmp_buf

longjmp — «откатывает» выполнение к сохранённому состоянию, как прыжок во времени



#include <stdio.h>
#include <setjmp.h>

jmp_buf jump_buffer;

void risky_function() {
printf("Готовимся к прыжку...\n");
longjmp(jump_buffer, 42); // Прыжок обратно в setjmp!
}

int main() {
int ret = setjmp(jump_buffer);
if (ret == 0) {
printf("Первая инициализация...\n");
risky_function();
} else {
printf("Вернулись с кодом: %d\n", ret); // Выведет 42!
}
return 0;
}


⚠️ Осторожно!

• Не заменяет исключения — нет вызова деструкторов (как в C++)
• Опасность утечек — если между setjmp и longjmp выделялась память, она не освободится
• Портит стек — может сломать логику функций

🛠 Где может пригодиться?

• Обработка критических ошибок (а-ля «аварийный выход»)
• Код для встраиваемых систем, где нужно быстро восстановить состояние
• Нестандартные хаки (но лучше так не делать 😈)

Библиотека C/C++ разработчика

BY Библиотека собеса по C++ | вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/cpp_interview_lib/861

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

Spiking bond yields driving sharp losses in tech stocks

A spike in interest rates since the start of the year has accelerated a rotation out of high-growth technology stocks and into value stocks poised to benefit from a reopening of the economy. The Nasdaq has fallen more than 10% over the past month as the Dow has soared to record highs, with a spike in the 10-year US Treasury yield acting as the main catalyst. It recently surged to a cycle high of more than 1.60% after starting the year below 1%. But according to Jim Paulsen, the Leuthold Group's chief investment strategist, rising interest rates do not represent a long-term threat to the stock market. Paulsen expects the 10-year yield to cross 2% by the end of the year. A spike in interest rates and its impact on the stock market depends on the economic backdrop, according to Paulsen. Rising interest rates amid a strengthening economy "may prove no challenge at all for stocks," Paulsen said.

How To Find Channels On Telegram?

There are multiple ways you can search for Telegram channels. One of the methods is really logical and you should all know it by now. We’re talking about using Telegram’s native search option. Make sure to download Telegram from the official website or update it to the latest version, using this link. Once you’ve installed Telegram, you can simply open the app and use the search bar. Tap on the magnifier icon and search for a channel that might interest you (e.g. Marvel comics). Even though this is the easiest method for searching Telegram channels, it isn’t the best one. This method is limited because it shows you only a couple of results per search.

telegram from cn


Telegram Библиотека собеса по C++ | вопросы с собеседований
FROM USA