lost again

B

Bill Cunningham

The compiler tells me in lines 19 and 20 there is a dereferencing to an
incomplete type. I don't know what that means much less than what to do with
it. Here's the code --

#include <stdio.h>

struct node *build(void)
{
struct node *root = NULL;
root = (struct node*)insert(root, 2);
root = (struct node*)insert(root, 1);
root = (struct node*)insert(root, 3);
return (root);
};

int maxDepth(struct node *node)
{
if (node == NULL) {
return 0;
}

else {
int ldepth = maxDepth(node->left);
int rdepth = maxDepth(node->right);
if (ldepth > rdepth)
return (ldepth + 1);

else
return (rdepth + 1);}
}

This with be compiled into an object file and compiled with another object
file and source to create a binary.

Bill
 
B

Ben Pfaff

Richard Heathfield said:
Bill Cunningham said:

That's your first syntax error right there. There's no such type as
"struct node *" in standard C, and you haven't provided a
definition yourself, so the type doesn't exist.

No, that line is not a syntax error, or any other kind of
constraint violation or undefined behavior, etc.

(It seems that you should know this.)
 
B

Bill Cunningham

No, that line is not a syntax error, or any other kind of
constraint violation or undefined behavior, etc.

(It seems that you should know this.)

I have this in another source file that compiles and assembles. Maybe
this is what the pros use headers for. Or maybe I should just slip this into
both .c files so I can make .o files from them.

struct node {
struct node *right;
struct node *left;
int count;
};

Should this be in this file also?

Bill
 
D

Donkey Hottie

Bill Cunningham said:
I have this in another source file that compiles and
assembles. Maybe this is what the pros use headers for.
Or maybe I should just slip this into both .c files so I
can make .o files from them.
struct node {
struct node *right;
struct node *left;
int count;
};

Should this be in this file also?

Bill

You should put it into node.h file and

#include "node.h" in the other files.
 
B

Beej Jorgensen

Bill Cunningham said:
Maybe this is what the pros use headers for.

It's definitely one of the things header files are used for.

And it's not just for pros, either. :)

-Beej
 
O

osmium

Bill Cunningham said:
I have this in another source file that compiles and assembles. Maybe
this is what the pros use headers for. Or maybe I should just slip this
into both .c files so I can make .o files from them.

struct node {
struct node *right;
struct node *left;
int count;
};

Should this be in this file also?

Well, as a last resort you could try to follow some of the advice you are
given from time to time. Here is an extract I sent you Dec 22, 2008. The
advise pertains to the same f***ing problem you are having right now.


#include <stdlib.h> #include <string.h> #include "s.h"


I am quite sure you have been told this before, but you seem to be
impervious to advise. Write one monolithic program and get it working.
Then, and only then, divide it into pieces. What does this mean? It means
to stuff the "s.h" thing in an incinerator. No, don't rename it. Get rid
of the damn thing!!!!! Whatever that implies. Don't ask why. Don't try to
figure out why. Just DO it!
<enquote>

Do you know what monolithic means? If not, can you find out? If you don't
understand the answers, say so!

From where you are in the learning curve, there is no reason in the world
for you to know that an 'o' file even exists.
 
N

Nick Keighley

    The compiler tells me in lines 19 and 20 there is a dereferencing to an
incomplete type. I don't know what that means much less than what to do with
it. Here's the code --

#include <stdio.h>

struct node *build(void)
{

what is node?
    struct node *root = NULL;
    root = (struct node*)insert(root, 2);

what is insert?
    root = (struct node*)insert(root, 1);
    root = (struct node*)insert(root, 3);
    return (root);

};

<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

tree 6
error in binary tree 13
simple BST implementation 18
Parse error? 3
Queue in C 25
main.c 14
nodes 4
correct tree 4

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,174
Latest member
BlissKetoACV
Top