Problem with Data structure in C - Trees


I have a problem with the definition and creation of data structures to use trees. The structures that I must use if or if and should not change is the following:

#define INT 1024
#define CHAR 1025
#define STRING 1032
#define LIST 1033
#define SET 1034

typedef struct dataType* dataPtr;
typedef struct stringType* stringPtr;
typedef struct charType* charPtr;

struct dataType{
    int nodeType;
    dataPtr dato;
    dataPtr sig;

struct stringType{
    int nodeType;
    char valor;
struct charType{
    int nodeType;
    char valor;

When I am going to create the tree as follows:

dataPtr aux;


And when I try the function in the main (that is, when compiling) I get the Windows error and this suggestion:

"return from incompatible pointer type [-Wincompatible-pointer-types]"

Does anyone know how I can solve it?

asked by Nicolas 25.05.2018 в 02:50

1 answer


dataPtr is already a pointer (set the typedef that says dataPtr equals dataType * ). On the other hand, the size you want to reserve is that of dataType , therefore at malloc you should pass the size of this structure.

The line that fails you should look like this:


While dataPtr * is a valid data type, it is equivalent to dataType ** (pointer to pointer).

answered by 25.05.2018 / 03:29