Essentially what I want to do is the C equivalent of:
translation_unit_list.cpp
std::vector<std::string> list;
bool addListItem(std::string str){
list.push_back(str);
return true;
}
int main(int argc, char **argv){
for(std::string translation_unit_name : list){
cout << translation_unit_name << endl;
}
return 0;
}
some_file.cpp
static bool initialized = addListItem("some file!");
some_file2.cpp
static bool initialized = addListItem("some other file!");
this way, translation_unit_list knows every translation unit that was compiled into the final executable. this allows the user to selectively compile what they want to be included. is there a way of achieving the same result with c?
Example desired behavior:
g++ -o exec1 translation_unit_list.cpp some_file.cpp
./exec1
some file!
g++ -o exec1 translation_unit_list.cpp some_file2.cpp
./exec1
some other file!
g++ -o exec1 translation_unit_list.cpp some_file.cpp some_file2.cpp
./exec1
some file!
some other file!