<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// gcc test.c -g -o test

int main(int argc, char *argv[]) {
  // Testing a little memcpy
  unsigned char c[8];
  
  void *a = malloc(sizeof(void));
  memcpy(c, &a, 8);
  
  printf("a: %p\n", a);
  for(int i = 0; i < 8; i++) {
    printf("%d: %u\n", i, c[i]);
  }
  
  void *b;
  memcpy(&b, c, 8);
  printf("b: %p\n", b);
  
  uint64_t d;
  d = (uint64_t)b;
  printf("d: 0x%llx\n", d);
  printf("d: %lld\n", d);
  
  // Make compiler treat it as a double without coercion/conversion.
  double f = *((double*)&d);
  printf("f: %f\n", f);
  // Proof that no conversion occurred.
  uint64_t g = *((uint64_t*)&f);
  printf("g: %lld\n", g);
  
  return 0;<commit_msg>Byte fiddling<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// gcc test.c -g -o test

void byte_fiddling() {
  uint32_t i = 0x0800;
  printf("i: 0x%lx\n", (unsigned long)i);
  
  void *p = &i;
  for(int o = 0; o < 4; o++) {
    // These are equivalent.
    //unsigned char c = ((unsigned char*)(&i))[o];
    unsigned char c  = *((unsigned char*)&i + o);
    // Have to cast to unsigned char before offsetting. This will make it go by
    // bytes instead of ints (4 bytes).
    printf("c[%d]: 0x%hhx\n", o, c);
  }
}

void memcpy_fiddling() {
  // Testing a little memcpy
  unsigned char c[8];
  
  void *a = malloc(sizeof(void));
  memcpy(c, &a, 8);
  
  printf("a: %p\n", a);
  for(int i = 0; i < 8; i++) {
    printf("%d: %u\n", i, c[i]);
  }
  
  void *b;
  memcpy(&b, c, 8);
  printf("b: %p\n", b);
  
  uint64_t d;
  d = (uint64_t)b;
  printf("d: 0x%llx\n", d);
  printf("d: %lld\n", d);
  
  // Make compiler treat it as a double without coercion/conversion.
  double f = *((double*)&d);
  printf("f: %f\n", f);
  // Proof that no conversion occurred.
  uint64_t g = *((uint64_t*)&f);
  printf("g: %lld\n", g);
}

int main(int argc, char *argv[]) {
  // memcpy_fiddling();
  byte_fiddling();
  return 0;
{'fraction_non_alphanumeric': 0.20921985815602837, 'fraction_numerical': 0.02127659574468085, 'mean_word_length': 2.8349514563106797, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3040099', 'n_tokens_mistral': 885, 'n_tokens_neox': 841, 'n_words': 236}