View previous topic :: View next topic |
Author |
Message |
MMurray
Joined: 19 Feb 2011 Posts: 22
|
Problem with pointers "Expecting a close paren " |
Posted: Sat Dec 10, 2011 10:53 am |
|
|
This code will not compile, I get the following error
*** Error 58 "Q Main.c" Line 101(13,14): Expecting a close paren
Line 101 is... addq(&front,&rear,1);
Does anyone have some insight to this issue?
Code: |
#include <16F877A.h>
#Fuses hs NOWDT
#USE delay(crystal=20mhz)
#use rs232(baud=9600, xmit=PIN_C7, rcv=PIN_C6)
#include "pins.h"
#include "main.h"
//==========================================================
void addq(struct node **f,struct node **r,int item)
{
struct node *q;
q=malloc(sizeof(struct node));
q->data=item;
q->link=NULL;
if(*f==NULL)
*f=q;
else
(*r)->link=q;
*r=q;
}
//===========================================================
int count(struct node *q)
{
int c=0;
while(q!=NULL)
{
q=q->link;
c++;
}
return c;
}
//==========================================================
void main ()
{
initMain();
initHdwr();
int q_count=0;
struct node *front,*rear;
int item=0;
front=NULL;
rear=NULL;
addq(&front,&rear,1);
while (TRUE)
{
q_count=count(front);
printf(lcd_putc,"%d",q_count);
wait;
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19529
|
|
Posted: Sat Dec 10, 2011 11:26 am |
|
|
CCS, has a relatively poor syntax checker.
If you have an error in a line, it merrily plods on trying to interpret subsequent lines, until something completely impossible happens. When this happens, it is at this line that it flags the error.
Hence your error is almost certainly referring to something many lines earlier.
First thing to do, is go through each of the include files, and use the tool that finds the matching brackets, and verify that the numbers do balance in each file. Then do the same in the main.
Best Wishes |
|
|
MMurray
Joined: 19 Feb 2011 Posts: 22
|
|
Posted: Sat Dec 10, 2011 12:02 pm |
|
|
Ran through that before posting, I just re-checked, I could not find any missing. Is there any thing else I should be looking for? |
|
|
MMurray
Joined: 19 Feb 2011 Posts: 22
|
|
Posted: Sat Dec 10, 2011 12:07 pm |
|
|
Ha Ha!!!! I found it!!!
I broke the line
struct node *front,*rear;
into...
struct node *front;
struct node *rear;
Thanks |
|
|
MMurray
Joined: 19 Feb 2011 Posts: 22
|
|
Posted: Sat Dec 10, 2011 12:11 pm |
|
|
No that did not help. I had commented out the offending line.
Help |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 10, 2011 3:15 pm |
|
|
I could reproduce the error putting in this definition
Code: | struct node {
int data;
int *link;
}; |
Replacing it with my preferred typedef (saving keystrokes) and changing it's instances respectively made CCS C accept the code.
Code: | typedef struct {
int data;
int *link;
} NODE;
void addq(NODE **f,NODE **r,int item)
|
Apparently, CCS C gets confused with multiple struct keywords in the formal function parameter list.
I wonder however, if using dynamic memory with PIC16 is a good idea? |
|
|
MMurray
Joined: 19 Feb 2011 Posts: 22
|
|
Posted: Sat Dec 10, 2011 4:41 pm |
|
|
Excellent! That has got it.
Thank you |
|
|
|