by hartcw · 11y ago · 0 comments
For example for generating a c/c++ enum:
enum example_t
{
#py \
for line in open('values.txt'): \
print('EXAMPLE_' + line.strip() + ',')
EXAMPLE_Max,
EXAMPLE_Unknown
};
Or alternatively to stuff it in a comment: enum example_t
{
/* py
for line in open('values.txt'):
print('EXAMPLE_' + line.strip() + ',')
*/
EXAMPLE_Max,
EXAMPLE_Unknown
};
If anyones interested, heres the python script I use to preprocess the c/c++ files https://github.com/hartcw/cppyThey should have copied Java's annotation model which makes a lot more sense.
These problems are exactly why this is unacceptable in Go. Go has the benefit of learning from C++'s mistakes and seeing other attempts at solutions to the problem. Language designers have made these mistakes before, realized they were mistakes, and come up with better alternatives. This is just another example of the Go team either being unaware of or ignoring decades of development in programming languages.
Something like PY_CODE(<blah>), for instance. That way it won't compile unless you run it through the preprocessor.
enum_example_t
{
#include "example_values.txt"
EXAMPLE_Max,
}
where example_values would have the strings 'EXAMPLE_foo,'?
Just wondering.