View Full Version : Resolved C - What to do about this warning: assignment from incompatible pointer type
bobleny
02-20-2010, 09:32 PM
I get this warning:
Test.c:417: warning: assignment from incompatible pointer type
From this line:
fileList = listFront;
Here is a code snippet:
pNode listFront = NULL;
pNode listEnd = NULL;
pContent fileList = NULL;
GetDirectory(dirLoc);
listFront = BuildDir(dirLoc, fileList, listEnd);
fileList = listFront;
BuildDir returns a pointer to a memory location.
I know it is just a warning, but I don't know what to do about it, if I need to do anything about it at all. I don't yet know when to ignore them and when not. I think warnings are potential misgivings.
Is there anything I can or need to do about it?
oracleguy
02-20-2010, 11:05 PM
Well what are pNode and pContent?
And yes warnings point to potential issues in your code. Ideally your code should produce no warnings.
bobleny
02-21-2010, 03:14 AM
pNode and pContent:
typedef struct content *pContent;
typedef struct node *pNode;
// Used to store the information about the contents of a directory
// For example, C:\Users\Default\Desktop\Read_Me.txt
typedef struct content
{
// Current path of the contents including the trailing slash
char *path; // C:\Users\Default\Desktop\ */
// The file name minus the path and extension
char *name; // Read_Me
// The extension of the file including the .(dot)
char *ext; // .txt
};
// Used as a pointer to the content struct
typedef struct node
{
// Next available memory location
pNode next;
// The memory location of the content struct
pContent data;
};
Again, I have attached the source file.
oracleguy
02-21-2010, 05:29 AM
Then yes what you are doing is bad. That really should be an error, I'm surprised your program doesn't seg fault. You can't just assign one struct with the totally different data members to another. (Well, you can but is very dangerous and really not something you should do)
With that assignment, if were to access the members in fileList, it would be using the memory from the other struct which uses a totally different layout.
bobleny
02-21-2010, 08:04 PM
What your saying is that my listFront is pointing to the first node structure.
fileList = listFront;
But fileList should be pointing to the first content structure which is pointed to by the first node structures data element.
fileList = listFront -> data;
If that is what you are saying, then my compiler agrees. I really should have thought of that on my own though! That wont happen again. lol
Thank you very much!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.