Jump to content

Bug? Accessing Array Of Structure By Pointer


Recommended Posts

When an array of structures is accessed by pointer (see below), compilation fails if the size of structure is > 4 bytes (32 bits).

 

#include <system.h>
typedef struct BigStruct {
 int x;
 int y;
// the next code line causes a compilation failure if 
// the commenting is removed
//  long z;
} t_BigStruct;

#define ELEMS 10
t_BigStruct MyStruct[ELEMS];

void main ()
{
 t_BigStruct * pSt=MyStruct;
 int i;
 for(i=0;i<ELEMS;i++) {
   pSt->x=-i;
   pSt->y=i;
// next code line will generate a compilation error if
// long z; is uncommented in the typedef above,
// is it because the structure size is now larger 
// than 32bits?
   pSt++;
 }
}

 

Compiler output and error message follows

Executing: "I:\Program Files\SourceBoost\boostc.pic18.exe" stsizeerror.c -O1  -W1  -t 18F4680
BoostC Optimizing C Compiler Version 6.32 (for PIC18 architecture)
[url=http://www.picant.com/c2c/c.html]http://www.picant.com/c2c/c.html[/url]
Copyright© 2004-2006 Pavel Baranov
Copyright© 2004-2006 David Hobday
Licensed to me under Single user Full License for 1 node(s)
Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited, Non commercial use only
stsizeerror.c
I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\stsizeerror.c(24:2): error: failed to generate expression
failure
BUILD FAILED: Thu Mar 09 17:28:43 2006

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...