f



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

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"=20
../Desktop/C Programs/HeadFirstTests.c: In function =91addFirst=92:
../Desktop/C Programs/HeadFirstTests.c:40:16: warning: assignment from incom=
patible pointer type [enabled by default]
../Desktop/C Programs/HeadFirstTests.c: In function =91printList=92:
../Desktop/C Programs/HeadFirstTests.c:51:7: warning: assignment from incomp=
atible pointer type [enabled by default]
"


/* This program builds=20
   a basic linked list.
   gcc "./Desktop/C Programs/HeadFirstTests.c" -o "./Desktop/C Programs/HFT=
" && "./Desktop/C Programs/HFT" =20
*/

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

typedef struct {           // Define a linked list node
     char *name;
     struct LLNODE *next;
}LLNODE;


void addFirst(char *data);  //Declare function prototypes
void printList(void);

LLNODE *head =3D NULL;  //Defind global pointer variable head

=20
int main(int argc, char *argv[])
{
=09
    addFirst("Johnson");
    addFirst("Robert");
    addFirst("Jerimiah");
    printList();
   =20
   =20
   return EXIT_SUCCESS;=20
}

void addFirst(char *data)
{
=09
	LLNODE *newNode;
	newNode =3D malloc(sizeof(LLNODE));
	newNode->name =3D data;
	newNode->next =3D head;  //Keep getting errors here.
	head =3D newNode;
=09
}

void printList(void)
{
	LLNODE *itr =3D head;
	while(itr !=3D NULL)
	{
		printf("%s\n", itr->name);
		itr =3D itr->next;  //Keep getting errors here.
	}
}
-- 
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.
0
galois271
1/5/2013 12:14:46 AM
comp.lang.c.moderated 1019 articles. 0 followers. Post Follow

6 Replies
646 Views

Similar Articles

[PageSpeed] 43

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.
0
Barry
2/26/2013 4:47:59 PM
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
>      char *name;
>      struct LLNODE *next;
> }LLNODE;

You are attempting to declare next with a yet undefined type. You must first 
make declare the struct.

/* Declaration of struct. */
struct LLNODE;

/* Declaration of typedef. */
typedef struct LLNODE LLNODE;

/* Definition of struct. */
struct LLNODE {
   char *name;
   struct LLNODE *next;
};

As a bonus tip, use of all upper case for names of structs is poor style. 
These should be reserved for macros.

-- 
JP
-- 
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.
0
LeJacq
2/26/2013 4:48:02 PM
On 2013-01-05, galois271@gmail.com <galois271@gmail.com> wrote:
> Any help here would be GREATLY appreciated!  Thanks!!!
>
> Here is my compiler response:

> ./Desktop/C Programs/HeadFirstTests.c:40:16: warning: assignment from incompatible pointer type [enabled by default]


> typedef struct {           // Define a linked list node
>      char *name;
>      struct LLNODE *next;
> }LLNODE;


Where is "struct LLNODE" defined ?  

( the above defines "LLNODE" but does not define "struct LLNODE" )

-- 
⚂⚃ 100% natural

--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
-- 
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.
0
Jasen
2/26/2013 4:51:22 PM
In article <clcm-20130104-0001@plethora.net>,  <galois271@gmail.com> wrote:
>
>typedef struct {           // Define a linked list node
>     char *name;
>     struct LLNODE *next;
>}LLNODE;
>

you're confused about typedefs and unnamed struct.

This does two things:
- make the language aware that struct LLNODE should be a valid struct
(for which you have *no definition*, but this doesn't prevent the compiler
from declaring a pointer to it)
- typedef an anonymous struct as the name LLNODE.

So, struct LLNODE and LLNODE are totally different beasties.
No wonder the compiler warns about it.

I'm a bit surprised it just warns.

If you really want typedefs, you could use
typedef struct LLNODE {
	char *name;
	struct LLNODE *next;
} LLNODE;

but it doesn't bring you much.
Especially since you're obviously a beginner, I'd recommend spelling it
out for now, avoiding the typedef, an using the complete struct name
all the way...
-- 
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.
0
espie
2/26/2013 4:51:28 PM
On 2013-01-05, galois271@gmail.com <galois271@gmail.com> wrote:
> warning: assignment from incompatible pointer type [enabled by default]
.....
>
> typedef struct {           // Define a linked list node
>      char *name;
>      struct LLNODE *next;
> }LLNODE;
....
> 	
> 	LLNODE *newNode;
> 	newNode = malloc(sizeof(LLNODE));
> 	newNode->name = data;
> 	newNode->next = head;  //Keep getting errors here.
....

Of course it complains. You have never declared "struct LLNODE". So
compiler does not believe that assigning "LLNODE*"  to "struct LLNODE*"
is acceptable. Standart way of handling this situation is

   typedef struct LLNODE LLNODE;
   struct LLNODE{
       char * name;
       LLNODE * next;
   }

or

   typedef struct LLNODE{
         char *name;
         struct LLNODE *next;
   }LLNODE;

-- 
Minds, like parachutes, function best when open
-- 
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.
0
Andrei
2/26/2013 4:51:31 PM
> typedef struct {           // Define a linked list node
>     char *name;
>     struct LLNODE *next;
> }LLNODE;

Where did you define a "struct LLNODE" (not LLNODE, *struct LLNODE*)?
Assigning a pointer to an LLNODE to a pointer to an undefined struct
type is going to draw the type of warning that you got.

If this is a C++ program, use a C++ compiler.
-- 
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.
0
gordonb
2/26/2013 4:51:36 PM
Reply:

Similar Artilces:

Disabling "incompatible pointer type" warning.
Hi all. Here is a simple code, which when compiled with gcc results in the warning "incompatible pointer type" for arg 1, as expected. But this is just what I want to do, because it makes it easy for me to handle the single dimensional stream I have as a multidimensional array inside the function func(). Now, I am just wondering if there is a way by which I can disable this incompatible pointer type warning in gcc. Any suggestions? Best regards, Prasanna. /*The Code*/ #include <stdio.h> void func(char [2][2]); int main() { char* src; int i; src = (char*)malloc...

["a", "b", "c", "d"] to "a, b, c, d"?
I want to process each element of an array, but the last element should be handled special. Here is an example: def p_ary(ary) str = "" ary.each do |elem| str << elem << ", " end str.chomp!(", ") str end so p_ary(["a", "f", "x", "test"]) produces "a, f, x, test". The code works, but isn't there an easier and more general way for this behaviour? martinus On Tue, 06 Apr 2004 04:23:22 -0700, Martin wrote: > I want to process each element of an array, but the last ele...

argument of type "double" is incompatible with parameter of type "mxArray **"
Hi : I'm trying to call imread with mexCallMATLAB but I always get the same error that can be ? . error: argument of type "double" is incompatible with parameter of type "mxArray **" The code is this <code> double imag; mxArray *str = mxCreateString("letras.tif"); mexCallMATLAB(1, &str, 1,imag, "imread"); printf("%f \n",imag); </code> "Rafael Valenzuela" <ravamo@gmail.com> wrote in message news:hrp1c3$lif$1@fred.mathworks.com... > Hi : > I'm trying to call imread with ...

Vexing GCC warnings: "assignment discards qualifiers from pointer target type"
Hi, I am unable to compile a large body of code with extremely pedantic compile time checks activate, so that warnings cause errors. With GCC 3.3.1, I do this with gcc -std=c99 -pedantic -Wall -Wunused -Werror -W -Wmissing-prototypes -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -c -o foo.o foo.c (This is basically what GSL recommendsd for scientific codes.) The problem is that I have a lot of code that generates these warnings: foo.c:258: warning: "assignment discards qualifiers from pointer target type" This warning occurs when I try to retur...

""""""""""""""""""""""ADD ME""""""""""""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfo Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... We look forward to build a ve...

Getting "incompatible types" warning on identical types!
At one point in my code, I have: VOID CALLBACK _cbSendMessageCallback(HWND h, UINT m, ULONG_PTR pcb, LRESULT res) { ... } Later, I have: HWND h = ...; UINT m = ...; WPARAM w = ...; LPARAM l = ...; RETVAL = SendMessageCallback(h, m, w, l, _cbSendMessageCallback, (ULONG_PTR)cb); where 'cb' is a pointer that I want to pass to the message callback function. When this compiles, it gives me a warning message: Ex.c(1024) : warning C4133: 'function' : incompatible types - from 'void (__stdcall *)(HWND,UINT,ULONG_PTR...

"""""""""ADD ME""""""""""
Hi , Hope you are doing great. Please let me take this opportunity to introduce myself, Iam Karthik working with BhanInfoi Inc, a NY based company. We have consultants on our bench on various technologies, my request is to add me to your distribution list and kindly do send me the requirements. i have the below list available 1. Mainframe 2. Java 3.. Financial Analyst 4. Data Architect If there is any vendor ship agreement which has to be signed then I would like to take an opportunity to represent my company and expect your cooperation... ...

compiler error: argument of type "VALUE *" is incompatible with parameter of type "VALUE"
I'm trying to build release 1.8.2 on a POSIX (1 and 2) based environment but have encountered a number of the following errors: SETUP_ARGS(node->nd_args); ^ "/home/ruby-1.8.2/eval.c", line 3206: error(252): argument of type "VALUE *" is incompatible with parameter of type "VALUE" SETUP_ARGS(node->nd_args); ^ "/home/ruby-1.8.2/eval.c", line 3206: error(252): argument of type "NODE *" is incompatible with parameter of type "VALUE" .... .... Thanks for the...

"column typing" or "multiline editing" and "smart typing"
(1) Is it possible to multiline editing like TextMate (http://macromates.com): http://macromates.com/images/inline/columns.gif ??? (2) And :-) http://macromates.com/images/inline/smart_typing.gif ??? How? -- Szymon Drejewicz Hi Szymon, > http://macromates.com/images/inline/columns.gif See the rectangle commands, C-x r C-h. > http://macromates.com/images/inline/smart_typing.gif See dynamic abbreviations, M-/. Herzliche Gr��e, Christoph -- Jenseits von falsch und richtig gibt es einen Ort. Dort treffen wir uns. Mevlana Celalettin Rumi Christoph Conrad <nospam@spamgo...

WARNING: column "footype" has type "unknown"
On 7.4.6, is there any problem with defining one column of a view to be a string literal? For example ... $ psql -c "create view fooview as select 'bar' as footype" WARNING: column "footype" has type "unknown" DETAIL: Proceeding with relation creation anyway. CREATE VIEW Or is this warning just noise in this case? Ed ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your ...

What does "Standard C", "K&R C" , "ANSI C" mean?
I am just wondering what the following terms usually mean: 1) "Standard C" 2) "K&R C" 3) "ANSI C" I am pretty sure "ANSI C" usually refers to the C89 standard, but what about the other two? What is the "saying" for C99 standard? Thank you On 17 Jan 2005 21:26:42 -0800, "Luke Wu" <LookSkywalker@gmail.com> wrote in comp.lang.c: > I am just wondering what the following terms usually mean: > > 1) "Standard C" The current version of the C language standard. This is now known as "ISO/IEC 9899:19...

Re: compiler error: argument of type "VALUE *" is incompatible with parameter of type "VALUE"
On May 5, 2005, at 2:44 PM, me2faster@excite.com wrote: I'm trying to build release 1.8.2 on a POSIX (1 and 2) based environment but have encountered a number of the following errors: SETUP_ARGS(node->nd_args); ^ "/home/ruby-1.8.2/eval.c", line 3206: error(252): argument of type "VALUE *" is incompatible with parameter of type "VALUE" Thanks for the help, We can't help you unless you provide more information. What OS? Compiler? Configuration options? etc etc etc. What you provide above isn't enough. -- ryand-ru...

Urgent Requirement in """""""""""""NEW YORK""""""""""""""""
Hello Partners, Please find the requirement below. Please send the updated resume along with rate and contact no. REQ#1: Title : Java Developer ( Rating Project) Duration : 6 months Rate : open Location : NY strong java, WebLogic 9.2, Web Services, Oracle REQ#2: Title : Java Developer Duration : 4 months Rate : open Location : NY Strong java, SQL REQ#3: Title : VB.Net Consultant Location : NY Duration : 4 months Rate : open Primarily looking at someone who has Excel, VB.net a...

strange warning "assignment of pointer"
I am trying to compile the following code: int * foo (short p_ []) { return p_; } and the compiler gives me the following warning: assignment of pointer to int to pointer to short Shouldn’t it be the other way round? ...

Web resources about - "warning: assignment from incompatible pointer type [enabled by default]" - comp.lang.c.moderated

Resources last updated: 2/8/2016 10:10:56 PM