rlang 0 Report post Posted November 2, 2004 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 Quote Share this post Link to post Share on other sites
Pavel 0 Report post Posted November 2, 2004 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 Quote Share this post Link to post Share on other sites
rlang 0 Report post Posted November 2, 2004 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 <{POST_SNAPBACK}> 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 Quote Share this post Link to post Share on other sites
Pavel 0 Report post Posted November 2, 2004 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 Quote Share this post Link to post Share on other sites
Pavel 0 Report post Posted November 2, 2004 Another workaround is to cast pointers to unsigned short: while ((unsigned short)EP0_start < (unsigned short)EP0_end) { ... } Regards, Pavel Quote Share this post Link to post Share on other sites
Pavel 0 Report post Posted November 3, 2004 Fixed. Fix will be available in 1.7 Regards, Pavel Quote Share this post Link to post Share on other sites