If you are just trying to achieve the 'enum hack', you should not have to do that in any recent compiler, as they will support static const member declarations.
class Foo
{
private:
static const int ARRAY_SIZE = 10;
int m_arr[ARRAY_SIZE];
};
Otherwise, doing an int cast like Jonathan Wood answered would work to change from a managed enum to an int.
Enumeration tools
arrays - Enum trick in C++/CLI - Stack Overflow
does the enum hack work in C? If so, is it supposed to work in VisualStudio 2003? - Stack Overflow
When are enums not a code smell?
Videos
Iโm struggling a little. Linking from one tool to another. I understand how to use the tools and in isolation they are ok, however enumerating from one to another with a logical process seems to throw me. Iโm struggling to connect the dots between different scans and how it might lead me to exploit the box.
Is there a process, a list of tools to work through that people could point me in the right direction of. What process do you like to follow. I always start with nmap but then get lost when it comes to following up the open ports. Iโm unaware of which one to pursue and go into a rabbit whole.
If you can advise the best list of tools to use would be greatly appreciated thank.
If you are just trying to achieve the 'enum hack', you should not have to do that in any recent compiler, as they will support static const member declarations.
class Foo
{
private:
static const int ARRAY_SIZE = 10;
int m_arr[ARRAY_SIZE];
};
Otherwise, doing an int cast like Jonathan Wood answered would work to change from a managed enum to an int.
Try:
arr[(int)EFoo.a];
Given the code in the question, GCC warns: warning: declaration does not declare anything for the enum line.
Place the enum outside the struct and you'll be fine.
typedef int P_O_U;
typedef unsigned long ULONG;
typedef unsigned short USHORT;
enum { MAXELEMENTS = 10 };
typedef struct _P_O
{
P_O_U elem;
ULONG id[MAXELEMENTS];
USHORT nid;
} P_O, *PP_O;
struct foo {
enum { MAXELEMENTS=10 };
long id[MAXELEMENTS];
};
enum hack like this is valid in C (But not a good style of code, see @Jonathan Leffler's comment). Because when id is defined, MAXELEMENTS qualifies with enumeration constant.
C99 6.2.1 Scopes of identifiers
Structure, union, and enumeration tags have scope that begins just after the appearance of the tag in a type specifier that declares the tag. Each enumeration constant has scope that begins just after the appearance of its defining enumerator in an enumerator list. Any other identifier has scope that begins just after the completion of its declarator.
And an enumeration is a type of integer constant.
C99 6.6 Constant expressions
An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, and floating constants that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert arithmetic types to integer types, except as part of an operand to the sizeof operator.
Finally, an integer constant can be used in array declarators, see C99 6.7.5.2 Array declarators .That's not surprising.