MC18 compiler. C pointer question.

Status
Not open for further replies.

HerbertMunch

New Member
Hi im trying to get a pointer to point at an array. Heres my code.

typedefs
Code:
typedef unsigned char bool;


//represents an individual menu item which belongs to a menu level
typedef rom struct MenuItem
{

	
		//bool. describes whether or not this node is a top level node.
		//i.e when MenuClick() is called on this item, topLevelHandler will be called 
		//and the current item will be stored in history
		char topLevel;
		//Pointer to an array of characters representing the menu item
		near rom char *text;
			//A pointer which points to the next level up in the menu heirarchy
		//Actually a MenuLevel pointer.
		near rom *subMenu;
			//Pointer to handler method that deals with the application specifics.
		void (*topLevelHandler)(void);

	
}MenuItem;

//represents a level of menu heirarchy.
typedef rom struct MenuLevel
{

    //The index of the current selected menu on this level
    char currentIndex;
    //The length of the item array specified by *items
    bool itemCount; 
    //Pointer to an array of menu items that represent this level
	rom MenuItem *items;
}MenuLevel;


Code:
//Pointer to the current menu level
struct MenuLevel *currentLevel;

	MenuItem *item = currentLevel->items;


The currentLevel->items array begins at memory location 0x83. however when i set the *item pointer = currentLevel->items, it actaullly points at 0xD0!

any ideas on what im doing wrong?

Many thanks.
 
My initial thought is that you can't write to a ROM structure. If you step through the disassembly listing you will see the compiler write to TBLPTR and associated registers but it does not do the required sequence required to write. (55 AA etc)

Mike.
 
oops!

thanks mate, ill try changing the code.

Chris
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…