![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
jgschmidt
Joined: 03 Dec 2008 Posts: 184 Location: Gresham, OR USA
|
Pointer problems - OOPS! User error. |
Posted: Mon Jul 09, 2012 5:05 pm |
|
|
Oops - this problem was caused by a conflict with an existing internal function: swap() is a CCS defined function
Hi,
I'm having some pointer problems. So I went to K&R to see what I might be doing wrong and wrote this minimalist pointer test code straight from the book, which generates the error. This compiles fine with PCC (Portable C Compiler) which I use for testing my hardware-independent C code.
Code: | // 616PtrTest.c
//
// K&R 2ed. Pointer test from pg.95-6
//
// Target: PIC16F616 at 8 MHz internal
// Compiler: CCS PCWH 4.130
// Programmer: PICkit2
//------ Setup for 16F616
#include <16F616.h>
#device ANSI // this doesn't make any difference
#FUSES INTRC_IO //Internal RC Osc, no output
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPUT //No Power Up Timer
#FUSES NOMCLR //Engages weak pullup
#FUSES NOBROWNOUT //No brownout reset
#use delay(internal=8M)
#use rs232( BAUD=38400, XMIT=PIN_A4, INVERT )
void swap( int *a, int *b )
{
int temp;
printf("fn1: %d %d\r\n",*a, *b);
temp = *a;
*a = *b;
*b = temp;
printf("fn2: %d %d\r\n",*a, *b);
}
main()
{
int i=3, j=5;
printf("before: %d %d \r\n",i,j);
swap( &i, &j );
printf("after: %d %d \r\n",i,j);
} |
Right now this doesn't even compile. I get the dreaded "Error 49: Expecting LVALUE..." on the function call. The &j is highlighted.
What am I doing wrong?
Thanks in advance for any help. _________________ Jürgen
www.jgscraft.com |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Tue Jul 10, 2012 1:42 am |
|
|
Your problem is simple. Nothing fundamental with the code, except one thing. Using the name 'swap' for the function. In CCS, 'swap' is a reserved keyword, for the function to swap nibbles in a byte. Hence it goes wrong.....
Call the function something like 'my_swap', and it'll all start working.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19360
|
|
Posted: Tue Jul 10, 2012 1:43 am |
|
|
I see you have spotted this.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|