Suppose a long time ago, I had created the following enumeration:
typedef enum
{
GeometricPoint,
GeometricLine,
GeometricSquare,
GeometricRectangle,
GeometricCircle
}GeometricFigures;
I introduced those a while ago within my awesome engine and now I have finally decided that people should not use GeometricSquare
anymore as that is covered by GeometricRectangle
already.
For a start, I would possibly change my enumeration towards something like this:
typedef enum
{
GeometricPoint,
GeometricLine,
GeometricRectangle,
GeometricSquare = GeometricRectangle,
GeometricCircle
}GeometricFigures;
That would certainly keep my awesome engine backwards compatible but on the other hand increase the legacy junk. Hence I would like to remove GeometricSquare
altogether in a foreseeable future. To make that obvious to the users of my engine, I would like to mark GeometricSquare
as being deprecated.
My goal is that the documentation (doxygen) as well as the code completion (Xcode) and last but not least the compiler (GCC) will make it obvious to the user that GeometricSquare
should not be used anymore and has been replaced by GeometricRectangle
.
For the documentation, I would simply use @deprecated
keyword;
typedef enum
{
GeometricPoint,
GeometricLine,
GeometricRectangle,
///@deprecated Has been replaced by GeometricRectangle
GeometricSquare = GeometricRectangle,
GeometricCircle
}GeometricFigures;
But how about Xcode and GCC?
Unfortunately, the usual GCC (method) attribute does not seem to do the job. Adding __attribute__((deprecated))
as drafted below causes a syntax error.
typedef enum
{
GeometricPoint,
GeometricLine,
GeometricRectangle,
GeometricSquare = GeometricRectangle __attribute__((deprecated)),
Parse Issue Expected }
GeometricCircle
}GeometricFigures;
So obviously that either does not work altogether or I am simply using it wrong.
Objective-C Language Enums Defining an enumtypedef NS_ENUM(NSUInteger, MyEnum) { MyEnumValueA = 0, MyEnumValueB = 5, MyEnumValueC = 10, }; You can also specify on the first value and all the following will use it with increment: typedef NS_ENUM(NSUInteger, MyEnum) { MyEnumValueA = 0, MyEnumValueB, MyEnumValueC, };
You can change default values of enum elements during declaration (if necessary).
Enum constants are implicitly static and final and you can not change their value once created.
On an 8-bit processor, enums can be 16-bits wide. On a 32-bit processor they can be 32-bits wide or more or less. The GCC C compiler will allocate enough memory for an enum to hold any of the values that you have declared. So, if your code only uses values below 256, your enum should be 8 bits wide.
I think you're attaching the __attribute__
bit to the wrong side of the assignment operator. This seems to work fine:
typedef enum
{
GeometricPoint,
GeometricLine,
GeometricRectangle,
GeometricSquare __attribute__((deprecated)) = GeometricRectangle,
GeometricCircle
}GeometricFigures;
and now assigning GeometricSquare
gives a compiler warning:
int fig = GeometricSquare; //'GeometricSquare' is deprecated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With