Jump to content
Sign in to follow this  
Andrew Leiper

Predecrement On A Struct Member Does Not Work

Recommended Posts

Hello again,

 

sourceboost V7.01

PIC18F2525

 

The if statement in the code below compiles so that s.DeviceAddress is decremented instead of s.NumRxDataBytes.

if (--s.NumRxDataBytes)

0010 0601 DECF gbl_s, F

0012 5202 MOVF gbl_s+D'1', F

0014 A4D8 BTFSS STATUS,Z

 

 

/////////////////////////////////////////////

#include <system.h>

 

typedef struct {

unsigned char DeviceAddress;

unsigned char NumRxDataBytes;

} TTestStruct;

 

TTestStruct s;

 

void main(void)

{

s.DeviceAddress = 1;

s.NumRxDataBytes = 0x55;

 

if (--s.NumRxDataBytes)

{

while(1);

}

}

/////////////////////////////////////////////

 

Andy Leiper

IET Ltd

Share this post


Link to post
Share on other sites

This problem also exists on V6.97

#include <system.h>

typedef struct {
unsigned char DeviceAddress;
unsigned char NumRxDataBytes;
} TTestStruct;

TTestStruct s;

void main(void)
{
s.DeviceAddress = 1;
s.NumRxDataBytes = 0x55;

if (--s.NumRxDataBytes)
{
	 while(1);
}
}

As does this but with a different error:

#include <system.h>

unsigned char s[] = {1,0x55};

void main(void)
{

if (--s[1])
{
	 while(1);
}
}

 

However this works:

#include <system.h>

typedef struct {
unsigned char DeviceAddress;
unsigned char NumRxDataBytes;
} TTestStruct;

TTestStruct s;

void main(void)
{
s.DeviceAddress = 1;
s.NumRxDataBytes = 0x55;

if (--s.NumRxDataBytes != 0)
{
	 while(1);
}
}

As does this:

#include <system.h>

unsigned char s[] = {1,0x55};

void main(void)
{

if (--s[1] != 0)
{
	 while(1);
}
}

 

Regards

 

davidb

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
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  

×