flatbuffers icon indicating copy to clipboard operation
flatbuffers copied to clipboard

There are much verbose of enum in generated C++ file.

Open haquocviet opened this issue 3 years ago • 6 comments

Hello all, I am using the latest flatbuffers compiler to generate C++ output file. For each enum I define in the schema file, the compiler generates much verbose stuffs related to the enum such as EnumValuesXYZ and EnumNameXYZ. Is there any option to supress those from compiling?.

Thanks.

haquocviet avatar Jun 14 '22 01:06 haquocviet

Is there a reason you don't want those? Compilers will strip out any unused functionality, so it isn't going to cause any bloat for your binaries to leave it.

dbaileychess avatar Jun 14 '22 23:06 dbaileychess

For the case of my schema file that has a lot of enums, the code for EnumValues-XYZ and EnumName-XYZ consumes about 15% to 20% of total generated code. That is pretty much for the features I do not need. The flatbuffers compiler already has many arguments giving users the flexibility whether they want to have a certain generated feature or not. That is great!. So it will be better if the library supports one more argument to enable/disable generating those features for enums.

haquocviet avatar Jun 15 '22 00:06 haquocviet

We have to balance code complexity with flatc complexity of managing multiple flags and their consequences. I don't see much gain for adding a flag. Disk space is cheap for storing source code, so 15-20% of source code bloat doesn't seem bad in my opinion.

That said, I would welcome a PR to change it.

dbaileychess avatar Jun 15 '22 04:06 dbaileychess

@haquocviet What if we put those functions in a preprocessor defined that you can undefined? That way we don't have to add yet another config option to flatc, but you can still disable those functions in your code?

dbaileychess avatar Sep 13 '22 06:09 dbaileychess

I understand that this way may save some work and won't break compatibility, it would be better if we can support using the switch via an argument like other arguments, but for any reason it can't be done soon, I am fine with your suggestion at this moment. Thanks for your consideration.

haquocviet avatar Sep 13 '22 07:09 haquocviet

Do we need to consider if we want to make some enums minified and some like normally what we have now all together?

rishabhdeepsingh avatar Oct 04 '22 20:10 rishabhdeepsingh