Compiler error

M

Maxx

Recently i'm getting this strange error while trying to compile a
binary tree program.
gcc -o -Wall wordcount wordcount.c
gcc: wordcount: No such file or directory
In file included from /usr/include/stdio.h:34,
from wordcount.c:8:
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
wordcount.c: In function ‘talloc’:
wordcount.c:58: warning: incompatible implicit declaration of built-in
function ‘malloc’

Couldn't figure out a way to get rid of it. here is the code:
struct tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
}

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

struct tnode *addtree(struct tnode *, char *);
void treeprint(struct tnode *);
struct tnode *talloc();

int main(int argc, char **argv)
{
struct tnode *root;
root=NULL;

while(--argc>0 )
{
root=addtree(root,*++argv);
}

treeprint(root);
return 0;
}

struct tnode *addtree(struct tnode *p,char *w)
{
int cond;
if(p==NULL)
{
p=talloc();
p->word=w;
p->count=1;
p->left=p->right=NULL;

}
else if((cond=strcmp(w,p->word))==0)
{
p->count++;
}
else if(cond<0)
{
p->left=addtree(p->left,w);
}
else if(cond>0)
{
p->right=addtree(p->right,w);
}
return p;
}

struct tnode *talloc(void)
{
return (struct tnode *) malloc(sizeof(struct tnode));
}

void treeprint(struct tnode *p)
{
if(p!=NULL)
{
treeprint(p->left);
printf("%s %4d\n",p->word,p->count);
treeprint(p->right);
}
}

Any help would be appreciated, this error is driving me nuts. Searched
it on google.....it returned that the error could be caused by some
bugs. But i think there's another story to it.

Thanks
Maxx
 
S

Seebs

Recently i'm getting this strange error while trying to compile a
binary tree program.
gcc -o -Wall wordcount wordcount.c
gcc: wordcount: No such file or directory

This is wrong:
gcc -o wordcount -Wall wordcount.c
The "-o" MUST be immediately adjacent to the name you want to use for
output.
In file included from /usr/include/stdio.h:34,
from wordcount.c:8:
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers

This sounds like your compiler is installed wrong or something.
wordcount.c: In function ?talloc?:
wordcount.c:58: warning: incompatible implicit declaration of built-in
function ?malloc?

You need said:
Couldn't figure out a way to get rid of it. here is the code:
struct tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
}

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

You should put your declaration UNDER the standard headers, by preference.
Any help would be appreciated, this error is driving me nuts. Searched
it on google.....it returned that the error could be caused by some
bugs. But i think there's another story to it.

Why do you think that?

-s
 
M

Moi

Recently i'm getting this strange error while trying to compile a binary
tree program.
gcc -o -Wall wordcount wordcount.c
gcc: wordcount: No such file or directory In file included from
/usr/include/stdio.h:34,
from wordcount.c:8:
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two or
more data types in declaration specifiers
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two or
more data types in declaration specifiers wordcount.c: In function
‘talloc’: wordcount.c:58: warning: incompatible implicit declaration of
built-in function ‘malloc’

Couldn't figure out a way to get rid of it. here is the code: struct
tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
}

;

HTH,
AvK
 
K

Keith Thompson

Seebs said:
This sounds like your compiler is installed wrong or something.

No, it's because of the syntax error in the code preceding the #include
You should put your declaration UNDER the standard headers, by preference.

That too. If nothing else, it probably would have resulted in a more
understandable error message, one not incorrectly pointing to system
code.

[...]
 
K

Keith Thompson

Keith Thompson said:
No, it's because of the syntax error in the code preceding the #include
<stdio.h>, specifically the missing semicolon on the struct declaration.

Let me rephrase that. Yes, it *sounds* like the compiler is installed
incorrectly, but that's not the real reason for the error.

[...]\
 
J

Jens Thoms Toerring

Maxx said:
Recently i'm getting this strange error while trying to compile a
binary tree program.

Others have already given you a few hints...
gcc -o -Wall wordcount wordcount.c
gcc: wordcount: No such file or directory

This is because the '-o' must come before the name of the output
file. You have it in front of '-Wall', so the compiler assumes
that you want an output file named '-Wall' and then considers
'wordcount' to be one of the files it is supposed to compile
(and in turn complains since there isn't any file with that
name yet). So make that

gcc -Wall -o wordcount wordcount.c

And since you already use '-Wall' why not go the whole way
and also add '-Wextra'?
In file included from /usr/include/stdio.h:34,
from wordcount.c:8:
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers
/usr/lib/gcc/i686-redhat-linux/4.4.4/include/stddef.h:211: error: two
or more data types in declaration specifiers

As other have suggested that's probably due to the missing
semicolon after the declaration of the 'tnode' structure.
wordcount.c: In function ‘talloc’:
wordcount.c:58: warning: incompatible implicit declaration of built-in
function ‘malloc’

I haven't seen any include for <stdlib.h> but that's were malloc()
is declared. If you forgot that the compiler assumes that malloc()
returns an int and takes a non-specified number of arguments.
That, in turn, can lead to nasty bugs. So never forget to include
<stdlib.h> when you use malloc() etc.

Regards, Jens
 
S

Seebs

Let me rephrase that. Yes, it *sounds* like the compiler is installed
incorrectly, but that's not the real reason for the error.

Good catch. The sad thing is, I shoulda caught that because I just
debugged a similar problem involving something bogus in front of a
declaration.

-s
 
M

Maxx

No, it's because of the syntax error in the code preceding the #include
<stdio.h>, specifically the missing semicolon on the struct declaration..

Let me rephrase that.  Yes, it *sounds* like the compiler is installed
incorrectly, but that's not the real reason for the error.

[...]\

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"


Oh yeah i completely forgot to put that semicolon. My bad.

My compiler is installed correctly cause it compiles other program
flawlessly.
 
M

Maxx

This is wrong:
        gcc -o wordcount -Wall wordcount.c
The "-o" MUST be immediately adjacent to the name you want to use for
output.


This sounds like your compiler is installed wrong or something.





You should put your declaration UNDER the standard headers, by preference..


Why do you think that?

Cause it ran other programs without any errors. Missing the semi colon
was throwing the error...
Thanks for your help
 
M

Maxx

Others have already given you a few hints...


This is because the '-o' must come before the name of the output
file. You have it in front of '-Wall', so the compiler assumes
that you want an output file named '-Wall' and then considers
'wordcount' to be one of the files it is supposed to compile
(and in turn complains since there isn't any file with that
name yet). So make that

gcc -Wall -o wordcount wordcount.c

And since you already use '-Wall' why not go the whole way
and also add '-Wextra'?


As other have suggested that's probably due to the missing
semicolon after the declaration of the 'tnode' structure.


I haven't seen any include for <stdlib.h> but that's were malloc()
is declared. If you forgot that the compiler assumes that malloc()
returns an int and takes a non-specified number of arguments.
That, in turn, can lead to nasty bugs. So never forget to include
<stdlib.h> when you use malloc() etc.

                                Regards, Jens

Yeah,Missing out the include for <stdlib.h> gave me that malloc error,
another stupid mistake by me. Wow this program taught me a hell lotta
stuffs.

Thanks
Regards Maxx
 
S

Seebs

My compiler is installed correctly cause it compiles other program
flawlessly.

I should point out: This isn't necessarily proof. A buggy compiler can
fail only under very rare circumstances, and it can still be an installation
problem...

-s
 

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


Members online

Forum statistics

Threads
473,954
Messages
2,570,114
Members
46,702
Latest member
VernitaGow

Latest Threads

Top