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.

C18 compiler. struct issues.

Status
Not open for further replies.

HerbertMunch

New Member
Im trying to make a member of this struct reference another instance of the same struct.

Code:
typedef struct MenuItem
{
	
	//Pointer to the an array of menuitems that represents the next level of heirarchy.
	MenuItem *nextLevel;
	
	

}MenuItem;

The compiler is not happy.
Can this not be done in c?
 
Would it be okay to do this instead, and then cast later?

Code:
typedef struct MenuItem
{
	
	//Pointer to the an array of menuitems that represents the next level of heirarchy.
	void *nextLevel;
	
	

}MenuItem;

Thanks
 
Would it be,
Code:
typedef struct MenuItem
{
	
	//Pointer to the an array of menuitems that represents the next level of heirarchy.
	near rom * MenuItem;

}MenuItem;

Mike.
 
BTW, I added a message print routine to your code that uses a rom pointer.

Code:
void PutMessage(char rom*);
void PutMessageAt(unsigned char,unsigned char,char rom*);


void main(void){
    InitLCD();
    PutMessage((rom char*) "Hello World!");
    PutMessageAt(3,2,(rom char*) "3 in on Line 2");
    while(1);
}

//Write a string to the LCD
void PutMessage(char rom *Message){
	while(*Message!=0)
	    WriteChar(*Message++);
}

//Set position and write string.
void PutMessageAt(unsigned char X,unsigned char Y,char rom *Message){
    WriteCommand(0x80+(--Y<<6)+--X);
	while(*Message!=0)
	    WriteChar(*Message++);
}

Mike.
 
Pommie said:
BTW, I added a message print routine to your code that uses a rom pointer.

Code:
void PutMessage(char rom*);
void PutMessageAt(unsigned char,unsigned char,char rom*);


void main(void){
    InitLCD();
    PutMessage((rom char*) "Hello World!");
    PutMessageAt(3,2,(rom char*) "3 in on Line 2");
    while(1);
}

//Write a string to the LCD
void PutMessage(char rom *Message){
    while(*Message!=0)
        WriteChar(*Message++);
}

//Set position and write string.
void PutMessageAt(unsigned char X,unsigned char Y,char rom *Message){
    WriteCommand(0x80+(--Y<<6)+--X);
    while(*Message!=0)
        WriteChar(*Message++);
}
Mike.

Nicely done Mike. A wonderful example using pointers which has thus far eluded and confounded me.
 
Pointers on the pic are confusing. The default is that pointers point to ram. I'm slowly getting comfortable with the types of pic pointers and have just realised that the cast on the function call is now not needed, this is from when I was trying everything to get it working.

So,
Code:
        PutMessage("Hello World!");

Should work fine.

Mike.
 
Pommie said:
Pointers on the pic are confusing. The default is that pointers point to ram. I'm slowly getting comfortable with the types of pic pointers and have just realised that the cast on the function call is now not needed, this is from when I was trying everything to get it working.

So,
Code:
        PutMessage("Hello World!");

Should work fine.

Mike.

ok thanks very much mate.:)
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top