Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 30th December 2007, 04:17 AM   (permalink)
Default C18 compiler. struct issues.

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?
HerbertMunch is offline  
Old 30th December 2007, 04:28 AM   (permalink)
Default

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
HerbertMunch is offline  
Old 30th December 2007, 05:01 AM   (permalink)
Default

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.
Pommie is online now  
Old 30th December 2007, 05:07 AM   (permalink)
Default

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 is online now  
Old 30th December 2007, 02:13 PM   (permalink)
Default

Ok thanks mike.

out of interest, which memory would my old code point to?

Thanks.
HerbertMunch is offline  
Old 30th December 2007, 02:28 PM   (permalink)
Default

Quote:
Originally Posted by Pommie
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.
Mike, K8LH is offline  
Old 30th December 2007, 03:27 PM   (permalink)
Default

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 is online now  
Old 31st December 2007, 02:44 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
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.
HerbertMunch is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
C18 compiler. Compiling custom libraries. HerbertMunch Micro Controllers 5 30th December 2007 04:29 AM
Problem setting up timer Interrupt using C18 compiler elec123 Micro Controllers 4 14th November 2007 11:59 AM
Regarding the CCS Compiler 3v0 Micro Controllers 5 24th March 2007 10:22 PM
Help, CCS PIC-C Compiler... Kenton Micro Controllers 17 3rd April 2006 12:48 AM
Atmel AVR free compiler and support free forum mramos1 Micro Controllers 3 24th October 2005 09:00 AM



All times are GMT. The time now is 01:36 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker