jweinst1
5/24/2018 - 7:15 PM

uses static buffer for number loading in C

uses static buffer for number loading in C

#include <stdio.h>

#define NUM_SIZE sizeof(double) + sizeof(unsigned char)

// example for loading marked binary data into a buffer.

typedef enum
{
   WindType_null,
   WindType_number
} WindType;

static unsigned char NUM_LOAD[NUM_SIZE] = {WindType_number};

void write_num(double num)
{
  *(double*)(NUM_LOAD + sizeof(unsigned char)) = num;
}


int main(void) {
  // Writes num to loader to make it [mark][num data] -> To write to larger buffer.
  write_num(30);
  unsigned char* reader = NUM_LOAD;
  for(int i = 0; i< sizeof(NUM_LOAD);i++) printf("%u\n", NUM_LOAD[i]);
  return 0;
}