Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

enum pointer

Status
Not open for further replies.

TucsonDon

Member
C:
typedef struct
{
    uint8_t prow[10];
    uint8_t pcolumn[10];
    uint8_t min;
    uint8_t max;
    ModeSec_t name;
    ModeSec_t disp[6];
    PLCDMove lcd_add;
    PputsLCD lcd_dis;
    unsigned set :1;
}TextDisplayAdd_t;


I am using this structure for elements of a menu with ModeSec_t being enumeration type. I want to use a different list for a sub menu w/o having to declare a new structure and current list has 50 elements. What is the most efficient way to point to either list
 
Separate the general typedef from the instance creation; eg.

C:
typedef struct TextStruct
{
    uint8_t prow[10];
    uint8_t pcolumn[10];
    uint8_t min;
    uint8_t max;
    ModeSec_t name;
    ModeSec_t disp[6];
    PLCDMove lcd_add;
    PputsLCD lcd_dis;
    unsigned set :1;
};

TextStruct TextDisplayAdd_t;

TextStruct TextMenu_t
 
rjenkinsgb thanks for the info. The issue that I have is ModeSec_t is a typedef'ed enum list. I want to change this to point to that list or another list w/o declaring another variable (i.e. the same variable for either list)
 
A union with pointers to both types?

You could use a void pointer, but you would need to cast it to the correct type every time it was used anywhere.
 
A union with pointers to both types?

You could use a void pointer, but you would need to cast it to the correct type every time it was used anywhere.
rjenkinsgb I am unsure how I need to do that, I know how to do a union, just not the way you suggest.
 
Something like:

union uptr {
TextDisplayAdd_t * txtptr;
ModeSec_t * modptr;
};

uptr.txtptr and uptr.modptr

Same memory location, but the context tells the compiler which type of data is being addressed.
 
Something like:

union uptr {
TextDisplayAdd_t * txtptr;
ModeSec_t * modptr;
};

uptr.txtptr and uptr.modptr

Same memory location, but the context tells the compiler which type of data is being addressed.

TextDisplayAdd_t is a structure type with ModeSec_t name and ModeSec_t disp[6] elements. ModeSec_t is an enumeration type. I want to make the array to point to ModeSec_t or another enumeration type.
 
ModeSec_t is an enumeration type. I want to make the array to point to ModeSec_t or another enumeration type.
Not quite sure I follow you here, but you can't have a pointer to an enum type. You can have a pointer to a variable of type ModeSec_t, but not ModeSec_t itself.

An enum type is just another definition for an int, so it has no storage. In your structure above, 'name' and 'disp[6]' are just fancy names for integers.
 
Not quite sure I follow you here, but you can't have a pointer to an enum type. You can have a pointer to a variable of type ModeSec_t, but not ModeSec_t itself.

An enum type is just another definition for an int, so it has no storage. In your structure above, 'name' and 'disp[6]' are just fancy names for integers.
tumbleweed thanks for the info
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top