Groups | Search | Server Info | Login | Register


Groups > comp.lang.c.moderated > #418

Re: "warning: assignment from incompatible pointer type [enabled by default]"

From Barry Schwarz <schwarzb@dqel.com>
Newsgroups comp.lang.c.moderated
Subject Re: "warning: assignment from incompatible pointer type [enabled by default]"
Date 2013-02-26 10:47 -0600
Organization SunSITE.dk - Supporting Open source
Message-ID <clcm-20130226-0001@plethora.net> (permalink)
References <clcm-20130104-0001@plethora.net>

Show all headers | View raw


On Fri, 4 Jan 2013 18:14:46 -0600 (CST), galois271@gmail.com wrote:

>Any help here would be GREATLY appreciated!  Thanks!!!
>
>Here is my compiler response:
>
>"gcc "./Desktop/C Programs/HeadFirstTests.c" -o "./Desktop/C Programs/HFT" && "./Desktop/C Programs/HFT" 
>./Desktop/C Programs/HeadFirstTests.c: In function ‘addFirst’:
>./Desktop/C Programs/HeadFirstTests.c:40:16: warning: assignment from incompatible pointer type [enabled by default]
>./Desktop/C Programs/HeadFirstTests.c: In function ‘printList’:
>./Desktop/C Programs/HeadFirstTests.c:51:7: warning: assignment from incompatible pointer type [enabled by default]
>"
>
>
>/* This program builds 
>   a basic linked list.
>   gcc "./Desktop/C Programs/HeadFirstTests.c" -o "./Desktop/C Programs/HFT" && "./Desktop/C Programs/HFT"  
>*/
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <string.h>
>
>typedef struct {           // Define a linked list node

At this point, you have "forward declared" a tagless structure type.

>     char *name;
>     struct LLNODE *next;

At this point, you have "forward declared" a structure type called
struct LLNODE.

>}LLNODE;

At this point, you have finished the definition of the tagless
structure and created a type LLNODE that is an alias for this
structure.  Note that LLNODE is a completely different type than
struct LLNODE.

>
>
>void addFirst(char *data);  //Declare function prototypes
>void printList(void);
>
>LLNODE *head = NULL;  //Defind global pointer variable head
>
> 
>int main(int argc, char *argv[])
>{
>	
>    addFirst("Johnson");
>    addFirst("Robert");
>    addFirst("Jerimiah");
>    printList();
>    
>    
>   return EXIT_SUCCESS; 
>}
>
>void addFirst(char *data)
>{
>	
>	LLNODE *newNode;
>	newNode = malloc(sizeof(LLNODE));
>	newNode->name = data;
>	newNode->next = head;  //Keep getting errors here.

next is a pointer to struct LLNODE.  head is a pointer to LLNODE.  As
noted above, the two are not the same or even compatible types.

>	head = newNode;
>	
>}

The solution to your problem is to add the tag LLNODE to you tagless
structure so that LLNODE and struct LLNODE refer to the same type.

-- 
Remove del for email
-- 
comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line.  Sorry.

Back to comp.lang.c.moderated | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

"warning: assignment from incompatible pointer type [enabled by default]" galois271@gmail.com - 2013-01-04 18:14 -0600
  Re: "warning: assignment from incompatible pointer type [enabled by default]" "LeJacq, Jean Pierre" <jeanpierre.lejacq@quoininc.com> - 2013-02-26 10:48 -0600
  Re: "warning: assignment from incompatible pointer type [enabled by default]" espie@lain.home (Marc Espie) - 2013-02-26 10:51 -0600
  Re: "warning: assignment from incompatible pointer type [enabled by default]" Barry Schwarz <schwarzb@dqel.com> - 2013-02-26 10:47 -0600
  Re: "warning: assignment from incompatible pointer type [enabled by default]" Jasen Betts <jasen@xnet.co.nz> - 2013-02-26 10:51 -0600
  Re: "warning: assignment from incompatible pointer type [enabled by default]" Andrei Voropaev <avorop@mail.ru> - 2013-02-26 10:51 -0600
  Re: "warning: assignment from incompatible pointer type [enabled by default]" gordonb.zh6m9@burditt.org (Gordon Burditt) - 2013-02-26 10:51 -0600

csiph-web