vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

c_preprocessor_embed.c (651B)


      1 // C preprocessor - binary resource inclusion
      2 
      3 // Source: https://en.cppreference.com/w/c/preprocessor/embed
      4 
      5 #include <stdint.h>
      6 #include <stdio.h>
      7 
      8 const uint8_t image_data[] = {
      9 #embed "image.png"
     10 };
     11 
     12 const char message[] = {
     13 #embed "message.txt" if_empty('M', 'i', 's', 's', 'i', 'n', 'g', '\n')
     14 ,'\0' // null terminator
     15 };
     16 
     17 void dump(const uint8_t arr[], size_t size)
     18 {
     19     for (size_t i = 0; i != size; ++i)
     20         printf("%02X%c", arr[i], (i + 1) % 16 ? ' ' : '\n');
     21     puts("");
     22 }
     23 
     24 int main()
     25 {
     26     puts("image_data[]:");
     27     dump(image_data, sizeof image_data);
     28     puts("message[]:");
     29     dump((const uint8_t*)message, sizeof message);
     30 }
     31