Skip to content

Instantly share code, notes, and snippets.

@frozenspider
Last active April 17, 2019 12:55
Show Gist options
  • Save frozenspider/d83c5e15fc05b2878bfa2fe6dcdeee4d to your computer and use it in GitHub Desktop.
Save frozenspider/d83c5e15fc05b2878bfa2fe6dcdeee4d to your computer and use it in GitHub Desktop.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef struct YBCStatusStruct {
int code;
char msg[0];
int sql_error_code;
} YBCStatusStruct;
typedef struct YBCStatusStruct* YBCStatus;
int main() {
std::string status_str = "Hello, world!";
size_t status_msg_buf_size = status_str.size() + 1;
YBCStatus ybc_status = reinterpret_cast<YBCStatus>(
malloc(sizeof(YBCStatusStruct) + status_msg_buf_size));
ybc_status->code = 123;
ybc_status->sql_error_code = 456;
cout << ybc_status->sql_error_code << endl; // prints 456
strncpy(ybc_status->msg, status_str.c_str(), status_msg_buf_size);
cout << ybc_status->sql_error_code << endl; // prints 1819043144
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment