Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-08-2003, 02:10 PM   #1
Registered: Sep 2003
Location: Newcastle upon Tyne
Distribution: Red Hat 9
Posts: 42

Rep: Reputation: 15
Newbie problem with pointers in C.

I am trying to teach myself C (using gcc 3.3.1). I am trying
to write a simple example that does a double linked list.
I seem to be falling at the first hurdle when I try and
create the pointer. My program is:

/*look at the use of structures and pointers to produce a
double linked list*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>

int main (void)
typedef struct
int time;
struct event *fptr,*bptr;
} event;

event *baseptr;

baseptr = (struct event *) malloc ( sizeof (struct event));


The compiler error is:

doublelinked.c:18: error invalid application of 'sizeof' to an incomplete type
doublelinked.c:18: warning assignment from incompatible pointer type

I have obviously done something daft, but would be grateful if some kind
person could tell me what is wrong.

Old 11-08-2003, 02:52 PM   #2
Registered: Jun 2002
Location: Orange County, CA
Distribution: Debian (squeeze), kernel 2.6.30-2-amd64
Posts: 32

Rep: Reputation: 15
Hi Chris,

The problem is that you're attempting to use the word "struct" in your call to malloc. The typedef for your structure creates an alias tagname for the unnamed structure, making the "struct" unecessary. So if you get rid of the "struct" words in your malloc line, it should compile clean.

Good luck,

-- ludwig
Old 11-08-2003, 03:00 PM   #3
Registered: Sep 2003
Location: Newcastle upon Tyne
Distribution: Red Hat 9
Posts: 42

Original Poster
Rep: Reputation: 15
Thanks Ludwig. You are right.

I copied the offending line straight out of Dennis Alcock's book
'Illustrating C'!

Best regards,


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointers Pointers Pointers urzumph Programming 9 03-11-2004 10:49 AM
Another C pointers question from a newbie chris.hicks Programming 6 11-11-2003 06:14 AM
Yet another pointers problem in C chris.hicks Programming 3 11-10-2003 09:35 AM
simple problem with pointers Jo_Nak Programming 2 06-17-2003 05:46 PM
Need some pointers in this problem (inside...) Vlad_M Linux - General 8 09-04-2002 04:45 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration