PLEASE HELP! Odd compilation error with GCC in Palm OS Dev. Suite

C

cpptutor2000

I am trying to create a simple linked list. The source code is provided
below. I receive the following error message: (Please see after source
code). I have marked the lines where the error occurs with three '***'.



#include "palmvector.h"

struct palmvectornode{
char ch;
struct palmvectornode *next;
};

void add(char ch){
struct palmvectornode *temp = NULL;
void * tmp = NULL;

if(start == NULL){
temp = (struct palmvectornode*)malloc(sizeof(struct

palmvectornode));
temp->ch = ch;
temp->next = NULL;
(struct palmvectornode*)start = (struct

palmvectornode*)temp;
(struct palmvectornode*)currpos = (struct

palmvectornode*)temp;
return;
}

if(start != NULL){
temp = (struct palmvectornode*)malloc(sizeof(struct

palmvectornode));
temp->ch = ch;
temp->next = NULL;
*** currpos->next = (struct palmvectornode *)temp;
(struct palmvectornode*)currpos = (struct

palmvectornode*)temp;
return;
}
}

unsigned int found(char chf){
struct palmvectornode* temp = (struct palmvectornode*)start;

while(temp != NULL){
if(temp->ch == chf){
return 1;
}
temp = temp->next;
}
return 0;
}

void deletepalmvector(){
struct palmvectornode *temp = (struct palmvectornode*)start;

while(start != NULL){
start = (struct palmvectornode*)start->next;
free(temp);
*** (struct palmvectornode*)temp = (struct
palmvectornode*)start;
}
}

.../src/palmvector.c: In function `add':
.../src/palmvector.c:25: error: dereferencing pointer to incomplete type
.../src/palmvector.c: In function `deletepalmvector':
.../src/palmvector.c:47: error: dereferencing pointer to incomplete type

Could someone please point out what might be wrong? THanks in advance
for
your help. I am using GCC 3.3.1 as packeaged in the Palm OS Developer
Suite.
 
R

Richard Tobin

*** currpos->next = (struct palmvectornode *)temp;

You haven't shown us the declaration of currpos, so we can't tell
what's wrong with it.

And what's this all about:
(struct palmvectornode*)currpos = (struct palmvectornode*)temp;

C doesn't let you use casts expressions as lvalues, even if gcc does
by default (try using -ansi -pedantic to get better error messages).

If the Palm Developer Suite required you to use this sort of perverted C,
you'd be better off asking in a palm-related newsgroup, because people
round here don't like that sort of thing!

-- Richard
 
C

CBFalconer

I am trying to create a simple linked list. The source code is
provided below. I receive the following error message: (Please see
after source code). I have marked the lines where the error occurs
with three '***'.
.... snip code ...

First, get rid of every one of those casts. None are needed, and
they generally provoke or conceal errors, such as failure ton
#include <stdlib.h>. Casts are evil things, eschew them unless you
have a very good and very clear reason for one. If you do use a
cast, write down the detailed reason in a comment. That may cure
you.
 
M

Martin Ambuhl

I am trying to create a simple linked list. The source code is provided
below. I receive the following error message: (Please see after source
code). I have marked the lines where the error occurs with three '***'.

Here is your code with the gratuitous and silly typecasts removed. You
should find that it compiles without a problem:

#if 0
/* mha: No such standard header */
#include "palmvector.h"
#endif
#include <stdlib.h> /* mha: added */

struct palmvectornode
{
char ch;
struct palmvectornode *next;
};

struct palmvectornode *start, *currpos; /* mha */

void add(char ch)
{
struct palmvectornode *temp = NULL;

if (start == NULL) {
temp = malloc(sizeof *temp); /* mha, check needed */
temp->ch = ch;
temp->next = NULL;
start = temp; /* mha */
currpos = temp; /* mha */
}
else {
temp = malloc(sizeof *temp); /* mha, check needed */
temp->ch = ch;
temp->next = NULL;
currpos->next = temp; /* mha */
currpos = temp; /* mha */
}
}

unsigned int found(char chf)
{
struct palmvectornode *temp = start; /* mha */
while (temp != NULL) {
if (temp->ch == chf)
return 1;
temp = temp->next;
}
return 0;
}

void deletepalmvector()
{
struct palmvectornode *temp = start; /* mha */
while (start != NULL) {
start = start->next; /* mha */
free(temp);
temp = start; /* mha */
}
}
 
C

cpptutor2000

Thanks to all who replied to my question. I have programmed in C/C++
for
a decade now, and hate casts too. Your suggestions really work well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,416
Latest member
LionelQ387

Latest Threads

Top