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

Discussion in 'C Programming' started by cpptutor2000@yahoo.com, Feb 5, 2005.

  1. Guest

    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.
    , Feb 5, 2005
    #1
    1. Advertising

  2. In article <>,
    <> wrote:

    >*** 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
    Richard Tobin, Feb 5, 2005
    #2
    1. Advertising

  3. CBFalconer Guest

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


    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    CBFalconer, Feb 6, 2005
    #3
  4. wrote:
    > 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 */
    }
    }





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



    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    Martin Ambuhl, Feb 6, 2005
    #4
  5. Guest

    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.

    Martin Ambuhl wrote:
    > wrote:
    > > 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 */
    > }
    > }
    >
    >
    >
    >
    >
    > >
    > >
    > >
    > > #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.
    > >

    >
    >
    > --
    > "If you want to post a followup via groups.google.com, don't use
    > the broken "Reply" link at the bottom of the article. Click on
    > "show options" at the top of the article, then click on the
    > "Reply" at the bottom of the article headers." - Keith Thompson
    , Feb 6, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    524
    Big Brian
    Oct 14, 2003
  2. Stimp
    Replies:
    0
    Views:
    368
    Stimp
    Sep 19, 2006
  3. Mabden

    Palm programming in C using GCC

    Mabden, Jul 6, 2005, in forum: C Programming
    Replies:
    0
    Views:
    276
    Mabden
    Jul 6, 2005
  4. Miroslaw Makowiecki
    Replies:
    4
    Views:
    353
    Jorgen Grahn
    Aug 2, 2007
  5. D. Krmpotic
    Replies:
    4
    Views:
    223
    NAKAMURA, Hiroshi
    Aug 3, 2007
Loading...

Share This Page