Skip to content

Instantly share code, notes, and snippets.

@jstine35
Last active July 14, 2019 13:25
Show Gist options
  • Save jstine35/dce098013e6bd28ceaa63c41a3945a1d to your computer and use it in GitHub Desktop.
Save jstine35/dce098013e6bd28ceaa63c41a3945a1d to your computer and use it in GitHub Desktop.
Macro to allow rapid creation of enum->string conversion tables in C++, using column editing and switch statements.
#pragma once
/////////////////////////////////////////////////////////////////////////////////////////////////
// CaseReturnString( caseName )
//
// Neat! Returns the case option as a string matching precisely the case label. Useful for logging
// hardware registers and for converting sparse enumerations into strings (enums where simple char*
// arrays fail).
//
#define CaseReturnString(caseName) case caseName: return # caseName
#define CaseReturnString2(ofs, caseName) case caseName: return # caseName + (ofs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment