__END__ (embedded data)

puts DATA.read
__END__
Hey oh!
Hey oh!

Mixing code and data in Ruby with DATA and __END__

Work perfectly with binary content as well.

(see also ruby-tricks)

C++

A less portable way to do this (even in C) with GNU ld is

$ ld -r -b binary -o file.o file.ext

then link in that in, and you have

extern const char _binary_file_ext_start[];
extern const char _binary_file_ext_end[];

to actually address the data

see also

Written on May 14, 2018, Last update on November 13, 2023
ruby tricks c++