Deep question for the REAL C GURU's out there ...
Ben Duncan
bns
Wed Feb 23 11:13:52 PST 2005
Ok, have been slag'ing away ( ;-> ) on my project.
Done a LOT of reading of other's C projects and AM always getting tripped
up by there usage of structptr1->structptr2->myitem.
Now, IS this not where a structure contains another structure and the above
is pointing to the sub-structure inside the main structure?
Now given that this is how I see everone else doing things and given the below
code: (see rest of email following code)
-------------------------------------------------------------------------------
/* C code snippet */
typedef struct Menu_Set Menu ;
typedef struct menu_line_item menulineitem ;
typedef struct Menu_Status menustat ;
struct Menu_Status
{
int ms_counter ;
int ms_users ;
char ms_status ;
char ms_message [ 80 ] ;
}
struct menu_line_item
{
int mli_lineid ;
char mli_displayname [ 16 ] ;
char mli_type [ 8 ] ;
char mli_program [ 24 ] ;
} ;
struct Menu_Set
{
char menu_heading [ 12 ] ; /* Also used as Menu ID */
int menu_item_count ; /* How many Line items ? */
menulineitem menusetlineitem [ 18 ] ;
menustat menuset_status ;
} ;
Menu menuStack[64]; /* We can have 64 menu's per system */
Menu *menuptr; /* Pointer to the MenuStack */
Menu *currentMenu ; /* Pointer to WHICH is current */
menustat *MenuStatus /* pointer to Menu Status stuff */
menulineitem *MenuItem; /* Pointer to the menulineitem */
int active_menu ; /* COunter of active menu's set up */
------------------------------------------------------------------------------
int idx, midx ;
for ( midx = 0 ; midx < active_menu ; midx++
{
/* < -- Start of PFM maybe ? */
menuptr = &menuStack[midx];
MenuStatus = &menuptr->menuset_status ;
/* Ok, watch WHAT I do here .... */
MenuStatus->ms_counter = 0 ;
for ( idx = 0; idx < menuptr->menu_item_count; idx++, mrows++ )
{
/* PAY CLOSE ATTENTION TO THE BELOW MenuItem CODE !!!!!!!! */
MenuItem = &menuptr->menusetlineitem[idx]; /* <---- LOOK CLOSELY !!! */
MenuStatus->ms_counter++ ; /* Again, is this trickery? */
if ( strcmp ( MenuItem->mli_type, HLINETYPE ) == 0 )
{
SLsmg_gotorc ( mrows, mcols );
SLsmg_set_color ( COLORSET_MENULINES );
SLsmg_draw_hline ( 16 );
............ or do other processing here ....
............ with if / elses's ............
.....
} /* WRAP UP Inside for
} /* Wrap up outside for */
------------------------------------------------------------------------------
Notice the MenuStatus and the MenuItem pointers. I can set these to directly to the
address of the information I need to access. And they WORK as should ( I have tested
this out).
Now my questions's are:
If this works, why does everone use the "aptr->bptr->item" method. Is that more the
political correct method? Is there anything BAD or BORKEN with doing the way I am doing it?
Is this going to be the same nightmare I faced 30 some odd years ago when I learned COBOL -
that there are so many ways to do things, you just have to pick a method and live with it?
Inquiring minds want to know .....
Thanks ...
--
Ben Duncan - VersAccounting Software LLC 336 Elton Road Jackson MS, 39212
"Never attribute to malice, that which can be adequately explained by stupidity"
- Hanlon's Razor
More information about the Linux-users
mailing list