Jump to content

Pointer Addition Fails With Structures


Recommended Posts

Pointer addition only seems to work for inbuilt data types, not for structures.

I've made a minimal test case to reproduce this, below.

I guess I could get around it by casting to a char* and adding on sizeof(s), then casting back... but that's kind of annoying!

The fact that "s++" works but "s+=1" doesn't definately looks like a bug!

 

#include <system.h>

struct ST
{
unsigned char x;
};

void main(void)
{
struct ST *s;		// Pointer to structure
unsigned char *c;	// Pointer to character

c++;	// OK
s++;	// OK
c += 1;	// OK
s += 1;	// error: illegal operation for operands 'unsigned char' and 'struct ST*'
}

 

Gives the result

 

Executing: "C:\Program Files\SourceBoost\boostc.pic18.exe" usb.c -O1 -W1 -t 18F2450

BoostC Optimizing C Compiler Version 6.81 (for PIC18 architecture)

(snip)

C:\MrZebra\RaveRaffe\PIC\USBRaffe\usb.c(29): error: illegal operation for operands 'unsigned char' and 'struct ST*'

C:\MrZebra\RaveRaffe\PIC\USBRaffe\usb.c(29:4): error: failed to generate expression

Link to post
Share on other sites
  • 1 month later...
Executing: "C:\Program Files\SourceBoost\boostc.pic18.exe" usb.c -O1 -W1 -t 18F2450

BoostC Optimizing C Compiler Version 6.81 (for PIC18 architecture)

(snip)

C:\MrZebra\RaveRaffe\PIC\USBRaffe\usb.c(29): error: illegal operation for operands 'unsigned char' and 'struct ST*'

C:\MrZebra\RaveRaffe\PIC\USBRaffe\usb.c(29:4): error: failed to generate expression

Fixed in V6.82.

 

Regards

Dave

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