Jump to content

Struct Self-referencing Problem


Recommended Posts

Two problems with elf-referencing structre access by pointer, both compiler fine in Borland C++ Builder 6 with a C language console app and compilation model of ANSI selcted.

 

following self-referenced struct code generates a compiler exception(?) trap under MPLAB IDE v7.31:

 

Error: Access violation at 0x0047028D (tried to read from 0x5C73747E), program terminated.

 

Soucre code is:

-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-

// structure self-references using stucts

 

#include <system.h>

#include <boostc.h>

 

struct stOne {

struct stOne * pSelf;

struct stTwo * pSecond;

struct stThree * pThird;

struct stFour * pFourth;

};

 

struct stTwo {

struct stTwo * pSelf;

struct stOne * pFirst;

struct stThree * pThird;

struct stFour * pFourth;

} ;

 

struct stThree {

struct stThree * pSelf;

struct stOne * pFirst;

struct stTwo * pSecond;

struct stFour * pFourth;

} ;

 

struct stFour {

struct stFour * pSelf;

struct stOne * pFirst;

struct stTwo * pSecond;

struct stThree * pThird;

} ;

 

struct stOne s1;

struct stTwo s2;

struct stThree s3;

struct stFour s4;

struct pstOne * stOne;

 

 

void main(void)

{

s1.pSelf =&s1;

s1.pSecond=&s2;

s2.pFirst =&s1;

s2.pSelf =&s2;

}

 

 

-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-

MPLAB IDE Project Ouput window [edited]:

BoostC Optimizing C Compiler Version 6.32 (for PIC18 architecture)

http://www.picant.com/c2c/c.html

Copyright© 2004-2006 Pavel Baranov

Copyright© 2004-2006 David Hobday

Licensed to ... under Single user Full License for 1 node(s)

Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited, Non commercial use only

main.c

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\Stucts 2\main.c(8:2): error: unknown struct 'struct stTwo'

BUILD FAILED: Tue Feb 28 16:40:42 2006

-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-

 

 

also if stucts are modified to typedefs causes following errors:

source code is:

-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-

// structure self-references using typedefs

 

#include <system.h>

#include <boostc.h>

 

struct stOne {

struct stOne * pSelf;

struct stTwo * pSecond;

struct stThree * pThird;

struct stFour * pFourth;

};

 

struct stTwo {

struct stTwo * pSelf;

struct stOne * pFirst;

struct stThree * pThird;

struct stFour * pFourth;

} ;

 

struct stThree {

struct stThree * pSelf;

struct stOne * pFirst;

struct stTwo * pSecond;

struct stFour * pFourth;

} ;

 

struct stFour {

struct stFour * pSelf;

struct stOne * pFirst;

struct stTwo * pSecond;

struct stThree * pThird;

} ;

 

struct stOne s1;

struct stTwo s2;

struct stThree s3;

struct stFour s4;

struct pstOne * stOne;

 

 

void main(void)

{

s1.pSelf =&s1;

s1.pSecond=&s2;

s2.pFirst =&s1;

s2.pSelf =&s2;

}

 

-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-

MPLAB IDE Project Ouput window [edited]:

BoostC Optimizing C Compiler Version 6.32 (for PIC18 architecture)http://www.picant.com/c2c/c.html

Copyright© 2004-2006 Pavel Baranov

Copyright© 2004-2006 David Hobday

Licensed to ... under Single user Full License for 1 node(s)

Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited, Non commercial use only

main.c

Starting preprocessor: "I:\Program Files\SourceBoost\pp.exe" "I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c" -i "I:\Program Files\SourceBoost\include" -d _PIC18F4680 -la -c2 -o main.pp -v -d _BOOSTC -d PIC18

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(6:8): error: unknown struct 'struct stOne'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(7:8): error: unknown struct 'struct stTwo'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(8:8): error: unknown struct 'struct stThree'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(9:8): error: unknown struct 'struct stFour'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(12:2): error: unknown data type 't_pstOne'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(18:8): error: struct stTwo struct type redefinition

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(26:2): error: unknown data type 't_pstThree'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(32:8): error: struct stFour struct type redefinition

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(39:1): error: unknown data type 't_stOne'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(40:1): error: unknown data type t_stTwo'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(41:1): error: unknown data type 't_stThree'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(42:1): error: unknown data type 't_stFour'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(47:2): error: unknown identifier 's1'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(47:2): error: failed to generate xpression

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(47:2): error: invalid operand 's1.pSelf'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(47:11): error: failed to generate expression

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(48:2): error: unknown identifier 's1'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(48:2): error: failed to generate expression

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(48:2): error: invalid operand 's1.pSecond'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(48:12): error: failed to generate expression

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(49:2): error: unknown identifier 's2'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(49:2): error: failed to generate expression

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(49:2): error: invalid operand 's2.pFirst'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(49:12): error: failed to generate expression

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(50:2): error: unknown identifier 's2'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(50:2): error: failed to generate expression

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(50:2): error: invalid operand 's2.pSelf'

I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(50:11): error: failed to generate expression

main.c success

failure

BUILD FAILED: Tue Feb 28 16:29:30 2006

-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-

Link to post
Share on other sites

BoostC compiler doesn't handle forward references to struct data types as in your code. C compilers didn't do this in the past but you are correct about the modern day C compilers. They seem to handle this feature now which means that they now do at least 2 compilation passes. I will add this feature in our internal todo list but can't tell when we implement it.

 

Regards,

Pavel

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...