Created
September 13, 2022 10:27
-
-
Save MXP2095onetechguy/1f3524ec67fb9a1a7806e7cb7d7e2477 to your computer and use it in GitHub Desktop.
Die in C and C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if !(defined(__cplusplus) || defined(c_plusplus) | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #else | |
| #include <cstdio> | |
| #include <cstdlib> | |
| #include <string> | |
| #endif | |
| #if defined(__cplusplus) || defined(c_plusplus) | |
| extern "C" { | |
| #endif | |
| void dierc(int rc, char* message){ | |
| using namespace std; | |
| if(message == NULL){ | |
| message = "Cheongsam Dies"; | |
| } | |
| fprintf(stderr, "%s\n", message); | |
| exit(rc); | |
| } | |
| void die(char* message){ | |
| using namespace std; | |
| dierc(EXIT_FAILURE, message); | |
| } | |
| #if defined(__cplusplus) || defined(c_plusplus) | |
| } | |
| void dierc(int rc, std::string message){ | |
| dierc(rc, &message[0]); | |
| } | |
| void die(std::string message){ | |
| die(&message[0]); | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment