📚Загадочная библиотека 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 выделялась память, она не освободится • Портит стек — может сломать логику функций
🛠Где может пригодиться?
• Обработка критических ошибок (а-ля «аварийный выход») • Код для встраиваемых систем, где нужно быстро восстановить состояние • Нестандартные хаки (но лучше так не делать 😈)
📚Загадочная библиотека 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 выделялась память, она не освободится • Портит стек — может сломать логику функций
🛠Где может пригодиться?
• Обработка критических ошибок (а-ля «аварийный выход») • Код для встраиваемых систем, где нужно быстро восстановить состояние • Нестандартные хаки (но лучше так не делать 😈)
Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.
How to Invest in Bitcoin?
Like a stock, you can buy and hold Bitcoin as an investment. You can even now do so in special retirement accounts called Bitcoin IRAs. No matter where you choose to hold your Bitcoin, people’s philosophies on how to invest it vary: Some buy and hold long term, some buy and aim to sell after a price rally, and others bet on its price decreasing. Bitcoin’s price over time has experienced big price swings, going as low as $5,165 and as high as $28,990 in 2020 alone. “I think in some places, people might be using Bitcoin to pay for things, but the truth is that it’s an asset that looks like it’s going to be increasing in value relatively quickly for some time,” Marquez says. “So why would you sell something that’s going to be worth so much more next year than it is today? The majority of people that hold it are long-term investors.”