Error: calling 'EDGE' with incomplete return type 'struct ptrEdge' on Depth-First Search Code

38 Views Asked by At

I'm working on a college assignment, and in order to do the assignment, I need to have a program that simulates Depth-First Search for graphs represented with adjacency lists. To be clear; the assignment is not to make the program, rather, I need to run the program with different graphs, and record data about those graphs. The textbook for my class shows various programs that I need to combine together, in order to create this DFS implementation, but none of the programs can compile by themselves.

I believe I'm close to having a working program. However, I still get 1 error when I attempt to compile; the error is: "error: calling 'EDGE' with incomplete return type 'struct ptrEdge'", on line 23 of "Program18.2.c" (my main program). Here is my code, which is split up into two files:

Program18.2.c:

#include <stdio.h>
#include "GRAPH.h" // Include the appropriate header file for Graph and Edge

//using namespace std;

static int cnt;
typedef struct STnode* link;

// Declare prev, Graph, and Edge.
int prev[MAX_V]; // Assuming MAX_V is the maximum number of vertices
typedef struct Graph* Graph; // Define the Graph structure appropriately
typedef struct Edge* ptrEdge;   // Define the Edge structure appropriately

void dfsR(Graph G, ptrEdge e);

void dfsR(Graph G, ptrEdge e) {
    link t;
    int w = e->w; // Assuming 'w' is a member of the Edge structure
    prev[w] = cnt++;

    for (t = G->adj[w]; t != NULL; t = t->next) {
        if (prev[t->v] == -1) {
            dfsR(G, EDGE(w, t->v)); // Assuming EDGE is a constructor for an Edge structure
        }
    }
}

int main() {
    // Initialize the 'prev' array, 'cnt', and create a Graph and an Edge.
    // Call dfsR with the appropriate parameters.

    return 0;
}

GRAPH.h:

#ifndef GRAPH_H
#define GRAPH_H

// Define the maximum number of vertices in the graph
#define MAX_V 100

// Define the Graph structure
struct Graph {
    int V;           // Number of vertices
    int E;           // Number of edges
    int** adj;       // Adjacency matrix, you may use an adjacency list or a different representation
};

// Define the Edge structure
struct Edge {
    int v;   // Source vertex
    int w;   // Destination vertex
    // Add other relevant members as needed
};

struct STnode {
    int v;
    struct STnode* next;
};

// Define a constructor for Edge
struct ptrEdge EDGE(int v, int w);

#endif

A while ago, I had the struct definition for 'Edge' In Program18.2.c as "typedef struct Edge* Edge;", as well as the definition for the constructor in GRAPH.h. I also had the "ptrEdge" objects referenced on lines 14 and 16 of Program18.2 as "Edge" objects.

Compiling this code also gave me one error on line 23, though slightly different: "passing 'struct Edge' to parameter of incompatible type 'Edge' (aka 'struct Edge*')".

So, I tried changing the Edge definitions to ptrEdge in the way I described above, and was thinking that the compiler was getting confused with so many "Edge" references. However, this doesn't appear to have been the case, and I now have the error I mentioned at the top of my post.

Does anyone know how I can resolve the error, and get this program to compile? Any feedback would be appreciated!

1

There are 1 best solutions below

1
Emilio Silva On

You defined your EDGE() function as returning struct ptrEdge.

However, your definition of ptrEdge is:

typedef struct Edge* ptrEdge;

This means that ptrEdge is an alias for struct Edge * and it therefore stands by itself:

ptrEdge EDGE(int v, int w);

To answer your second question, I got it to compile by making the change above in both (.c and .h) files, then I moved the ptrEdge and link typedefs to GRAPH.h and changed the type Graph to:

typedef struct STnode* link;

struct Graph {
    int V;           // Number of vertices
    int E;           // Number of edges
    link* adj;       // Adjacency matrix, you may use an adjacency list or a different representation
};

Now the only message I get is the missing definition of EDGE().