Jump to content
Sign in to follow this  
rlang

Compiler Error?

Recommended Posts

There seems to be a lot of forum traffic on pointers. I was trying to compare two pointer values in the program below and the compiler bawked with "DEBUG.c(12:19): error: failed to generate expression" on the WHILE statement. Is this a 1.6 compiler problem?

 

Rob

 

 

#include <system.h>

const char * EP0_start;

const char * EP0_end;

const char x=10;

const char y=20;

 

void main()

{

EP0_start=&x;

EP0_end=&y;

 

while (EP0_start < EP0_end)

{

++ EP0_start;

}

}

 

Compiling...

C:\SBOOST\boostc.pic16.exe -t PIC16C745 DEBUG.c

BoostC Optimizing C Compiler Version 1.6 Alpha (for PIC16 architecture)

DEBUG.c(12:19): error: failed to generate expression

failure

Done

Share this post


Link to post
Share on other sites

Yes this looks like an error but this kind of comparisson is probably never used in the code (at least I never ever used something like this). I'm curious when you need to compare pointers?

 

Regards,

Pavel

Share this post


Link to post
Share on other sites
Yes this looks like an error but this kind of comparisson is probably never used in the code (at least I never ever used something like this). I'm curious when you need to compare pointers?

 

Regards,

Pavel

 

Coding similar to this is found in a USB interface program. The two pointers mark the beginning and the end of the data to be transmitted. Since the entire block of data can not be transmitted at one time, EP0_start is updated on each transmission to reflect the data remaining to be transmitted. When EP0_start = EP0_end, then the entire block of data is transmitted and it is time to exit the WHILE. If the compiler does not support this I would be happy for a workaround.

 

Rob

Share this post


Link to post
Share on other sites
Coding similar to this is found in a USB interface program.  The two pointers mark the beginning and the end of the data to be transmitted.  Since the entire block of data can not be transmitted at one time, EP0_start is updated on each transmission to reflect the data remaining to be transmitted.  When EP0_start = EP0_end, then the entire block of data is transmitted and it is time to exit the WHILE.  If the compiler does not support this I would be happy for a workaround.

 

Hmmm I see now but I still don't recommend this practice even when this bug is fixed. Pointers are 2 bytes long and operations on such variables generates much more code than if 1 byte vars are used. If buffer is less than 256 bytes long a simple for loop with char counter will work more efficient:

char i;
for( i = 0; i < BUFLEN; i++ )
{
   ...
}

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Another workaround is to cast pointers to unsigned short:

 

while ((unsigned short)EP0_start < (unsigned short)EP0_end)
{
  ...
}

 

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