locked
enum default type options RRS feed

  • Question

  • Can I set some options in Visual Studio 2010 to change default enum size to 1 byte. Code changes is prohibited
    Tuesday, September 15, 2015 12:35 PM

Answers

  • Short answer: No.  The compiler picks a size it feels appropriate (VC++ always picks 4 bytes, AFIK).

    If you could change the code you could use

    enum fruit : char{ apple, banana, orange };

    This is a non-standard extension to C++03 that Visual C++ supports.

    I am a little curious what scenario permits you to recompile code in a way that changes the sizes of variables and layout of structures but does not permit you to modify the source code.  I really cannot think of a case that this would be successful to achieve anything useful, other than to cause random crashes if you try to link that code to something else that expected the old sizes.


    • Edited by SimonRev Tuesday, September 15, 2015 1:59 PM
    • Proposed as answer by Shu 2017 Thursday, September 17, 2015 7:37 AM
    • Marked as answer by Shu 2017 Thursday, September 24, 2015 1:33 AM
    Tuesday, September 15, 2015 1:58 PM