niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » C
Help getting this to compile
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
Author Message
Allan M. Bruce
*nix forums beginner


Joined: 26 May 2006
Posts: 15

PostPosted: Thu Jul 20, 2006 10:31 am    Post subject: Help getting this to compile Reply with quote

I have a small implementation of a queue which I am trying to get to compile
but cant figure out why it doesnt work. I have copied the minimum
compilable code below. On gcc I get

temp2.c: In function `pop':
temp2.c:24: warning: initialization from incompatible pointer type
temp2.c:25: warning: assignment from incompatible pointer type
temp2.c: In function `destroy':
temp2.c:38: error: dereferencing pointer to incomplete type

In line 24, I am trying to intialise e which is an (entry *) to *xiQueue
which is a *(entry **) which should be an (entry *), no?
In line 38, I am dereferencing xiQueue which should give me an (entry *) so
I can access the members of the struct with ->, no?

In Visual C I get even more errors:

queue.c(24): error C2275: 'entry' : illegal use of this type as an
expression
queue.c(24): error C2065: 'e' : undeclared identifier
queue.c(25): error C2223: left of '->nextNode' must point to struct/union
queue.c(26): error C2223: left of '->data' must point to struct/union
queue.c(27): warning C4022: 'free' : pointer mismatch for actual parameter 1
queue.c(3Cool: error C2037: left of 'nextNode' specifies undefined
struct/union 'entry'

Perhaps I am misunderstanding how to use typedef to make the queue
effectively an entry *. Can anybody help?
Thanks
Allan



#include <stdio.h>
#include <stdlib.h>

/*****************************************/
enum ERROR_CODES {ERROR, SUCCESS};

typedef struct entry *queue;

int pop(queue *, int *);
void destroy(queue *);
/*****************************************/

typedef struct tagEntry
{
int data;
struct tagEntry *nextNode;
} entry;

int pop(queue *xiQueue, int *xoData)
{
if (xiQueue == NULL)
return ERROR;

entry *e = *xiQueue;
*xiQueue = e->nextNode;
*xoData = e->data;
free(e);

return SUCCESS;
}

void destroy(queue *xiQueue)
{
if (xiQueue == NULL)
return;

int lDummy;
while ((*xiQueue)->nextNode != NULL)
pop(xiQueue, &lDummy);
xiQueue = NULL;
}

int main(void)
{
return 0;
}
Back to top
Richard Bos
*nix forums Guru


Joined: 21 Feb 2005
Posts: 1031

PostPosted: Thu Jul 20, 2006 10:47 am    Post subject: Re: Help getting this to compile Reply with quote

"Allan M. Bruce" <allanmb@TAKEAWAYdsl.pipex.com> wrote:

Quote:
In Visual C I get even more errors:

queue.c(24): error C2275: 'entry' : illegal use of this type as an
expression
queue.c(24): error C2065: 'e' : undeclared identifier
queue.c(25): error C2223: left of '->nextNode' must point to struct/union
queue.c(26): error C2223: left of '->data' must point to struct/union
queue.c(27): warning C4022: 'free' : pointer mismatch for actual parameter 1

Compiling as C++, are you?

Quote:
queue.c(3Cool: error C2037: left of 'nextNode' specifies undefined
struct/union 'entry'

#include <stdio.h
#include <stdlib.h

/*****************************************/
enum ERROR_CODES {ERROR, SUCCESS};

typedef struct entry *queue;
^^^^^^^^^^^^


Quote:
int pop(queue *, int *);
void destroy(queue *);
/*****************************************/

typedef struct tagEntry
^^^^^^^^^^^^^^^
{
int data;
struct tagEntry *nextNode;
} entry;
^^^^^


That's your problem. There's no such thing as a struct entry. It's
either an entry, but you can't use that before it's defined; or it's a
struct tagEntry. It should be

typedef struct tagEntry *queue;

Alternatively, you could replace struct tagEntry with struct entry in
the struct definition. Structure tags live in a namespace of their own,
so struct entry and typedef entry do not clash.

Richard
Back to top
Allan M. Bruce
*nix forums beginner


Joined: 26 May 2006
Posts: 15

PostPosted: Thu Jul 20, 2006 11:12 am    Post subject: Re: Help getting this to compile Reply with quote

"Richard Bos" <rlb@hoekstra-uitgeverij.nl> wrote in message
news:44bf5e60.676627919@news.xs4all.nl...
Quote:
"Allan M. Bruce" <allanmb@TAKEAWAYdsl.pipex.com> wrote:

In Visual C I get even more errors:

queue.c(24): error C2275: 'entry' : illegal use of this type as an
expression
queue.c(24): error C2065: 'e' : undeclared identifier
queue.c(25): error C2223: left of '->nextNode' must point to struct/union
queue.c(26): error C2223: left of '->data' must point to struct/union
queue.c(27): warning C4022: 'free' : pointer mismatch for actual
parameter 1

Compiling as C++, are you?

queue.c(3Cool: error C2037: left of 'nextNode' specifies undefined
struct/union 'entry'

#include <stdio.h
#include <stdlib.h

/*****************************************/
enum ERROR_CODES {ERROR, SUCCESS};

typedef struct entry *queue;
^^^^^^^^^^^^

int pop(queue *, int *);
void destroy(queue *);
/*****************************************/

typedef struct tagEntry
^^^^^^^^^^^^^^^
{
int data;
struct tagEntry *nextNode;
} entry;
^^^^^

That's your problem. There's no such thing as a struct entry. It's
either an entry, but you can't use that before it's defined; or it's a
struct tagEntry. It should be

typedef struct tagEntry *queue;

Alternatively, you could replace struct tagEntry with struct entry in
the struct definition. Structure tags live in a namespace of their own,
so struct entry and typedef entry do not clash.

Richard

Hehe, as easy as that - I thought it might be!
Thanks Richard
Allan
Back to top
Martin Ambuhl
*nix forums Guru


Joined: 20 Feb 2005
Posts: 582

PostPosted: Thu Jul 20, 2006 8:22 pm    Post subject: Re: Help getting this to compile Reply with quote

Allan M. Bruce wrote:
Quote:

Perhaps I am misunderstanding how to use typedef to make the queue
effectively an entry *.

Yes, you are:

Quote:
typedef struct entry *queue;
The above is wrong. 'struct entry' is meaningless. Try, if you _must_

use promiscuous typedefs,

typedef struct tagEntry *queue;


Quote:
typedef struct tagEntry
{
int data;
struct tagEntry *nextNode;
} entry;
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [4 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 6:35 pm | All times are GMT
navigation Forum index » Programming » C
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts python compile code object -- reverse how to leo python 1 Wed Jul 19, 2006 10:34 pm
No new posts Mplayer-gtk-esound 0.99.8 cannot compile on FreeBSD 4.11 Young Coot FreeBSD 8 Tue Jul 18, 2006 7:21 pm
No new posts current kernel compile problem Ian Bell NetBSD 0 Sun Jul 16, 2006 8:50 pm
No new posts Why doesn't this code compile? fungus C++ 11 Sun Jul 16, 2006 6:50 pm
No new posts how to compile apache with out depending on the mechine n... Meir Yanovich Apache 1 Sun Jul 16, 2006 9:22 am

Mortgages | Home Loan | Loans | Cheap Car Insurance | Mortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1696s ][ Queries: 16 (0.0790s) ][ GZIP on - Debug on ]