Hacker News new | ask | show | jobs
by jjgreen 1248 days ago
One .cc/.h pair, one object

Not always the case; I have a project with

    default.o: default.yaml
             $(LD) -r -b binary -o default.o default.yaml
and a default.h containing

    extern const char _binary_default_yaml_start[];
    extern const char _binary_default_yaml_end[];

    #define PARAM_YAML _binary_default_yaml_start
    #define PARAM_YAML_LEN (_binary_default_yaml_end - _binary_default_yaml_start)
this used in the main code as

   fwrite(PARAM_YAML, 1, PARAM_YAML_LEN, stdout);
printing the contents of the yaml file to stdout.
2 comments

The point is that the tool is opinionated and demands that this be the case for projects that work with it. Not that the author believes all .cc / .h files work that way.

Your use case would be served by C23's #embed [1]. The same thing has been proposed for C++ but repeatedly kicked down the road because the standardisation committee wanted to make it more general even though no one had any demand for that so they didn't know what it would look like. (C++ standardisation in a nutshell.)

[1] https://thephd.dev/finally-embed-in-c23

Wow, I didn't know about #embed, that will make life so much easier -- thanks!
So, you do things in a way that would not support this approach. She’s not saying “this is always how it’s done”, she’s explaining what practices you would need to commit to in order for her approach to be viable:

> “If you want something like this to work, you have to commit to a certain amount of consistency in your code base. You might have to throw out a few really nasty hacks that you've done in the past. It's entirely likely that most people are fully unwilling or unable to do this, and so they will continue to suffer. That's on them.”