Jump to content
Sign in to follow this  
trossin

Access Violation When Compiling Code

Recommended Posts

Bug description:

Tried to help someone fix some code that would not compile by trying to fix it on Linux using gcc. Got it to compile on gcc so I tried it in source boost and got an access violatoin

 

Steps to reproduce:

#include <system.h>

typedef struct {
unsigned char note;
unsigned char velocity;
} MIDI_NOTE;

typedef struct {
MIDI_NOTE midi;
int time;
struct NOTE_NODE* next;
} NOTE_NODE;

NOTE_NODE notes[8];

void main()
{
   notes[0].time = 0;
   while(1);
}

 

Expected behaviour:

It should compile.

 

Is the problem 100% reproduceable:

yes

 

IDE version: 6.40

Compiler: BoostC

Compiler version: 6.4

Target: PIC12F675

OS: WinXP Pro

 

Comments:

Access violatoin at 0x004aae56 (read of 0x72506391) pop up.

 

Output from compiler:

.....CBBug1.c(11:1): error: unknown struct 'struct NOTE_NODE'

.....boostc.pic16.exe" CBBug1.c -t PIC12F675

Exit code was -1073741819

 

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

This code compiles and seems to work as expcected:

 

#include <system.h>

typedef struct {
 unsigned char note;
 unsigned char velocity;
} MIDI_NOTE;

typedef struct NN_S {
 MIDI_NOTE midi;
 int time;
 struct NN_S* next;
} NOTE_NODE;

NOTE_NODE notes[8];

int temp_time;

void main()
{
  notes[0].time = 0;
  notes[0].next = &notes[6];
  notes[6].time = 6;
  temp_time = notes[0].next -> time;
  while(1);
}

 

It looks like BoostC wants explicit structure tags if you need to define a self referenced link list data type.

Share this post


Link to post
Share on other sites

This is not an error. You try to use NOTE_NODE before it's been typedefed and compiler reports an error because at this point it doesn't know yet what NOTE_NODE is.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
This is not an error. You try to use NOTE_NODE before it's been typedefed and compiler reports an error because at this point it doesn't know yet what NOTE_NODE is.

 

Regards,

Pavel

 

Does "this" refer to my access violation bug or to cac001's message. If it refers to the access violation, I feel that anytime the compiler creates an exeption that the OS has to clean up it is an error even if thrown bogus input. Also, gcc seems to handle the code fine as it seems to be able to recursively unwind self referencing structures.

Edited by trossin

Share this post


Link to post
Share on other sites
Does "this" refer to my access violation bug or to cac001's message...

 

Sorry for the confusion. Any access violation or exceptions or crashes in the compiler are problems and we are more than happy to get reports about them. Out philosophy is that any such problem is a serious one and should be fixed as soon as practical. In the corrent working compiler this crash has been fixed and I just forgot that your post actually included 2 issues: crash and unrecognized typedef and was addressing the second issue. Regarding it though gcc may handle such code this doesn't mean that this is standard behavoiur and others should do it as well. For example MSVC 8.0 doesn't handle such code. BoostC doesn't handle it either. Technically it's possible to change BoostC to handle it but the effort might be relatively big and may require another parsing pass that will increase compilation time. This makes it not very practical to fix this. Beside it's very easy to modify code to make it compiler and portable between compilers by adding struct name and referring to this struct name in the declaration.

 

Regards,

Pavel

Share this post


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...
Sign in to follow this  

×
×
  • Create New...