Skip to content

Instantly share code, notes, and snippets.

@MXP2095onetechguy
Created September 13, 2022 10:27
Show Gist options
  • Select an option

  • Save MXP2095onetechguy/1f3524ec67fb9a1a7806e7cb7d7e2477 to your computer and use it in GitHub Desktop.

Select an option

Save MXP2095onetechguy/1f3524ec67fb9a1a7806e7cb7d7e2477 to your computer and use it in GitHub Desktop.
Die in C and C++
#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