Subject: Re: how to correct for compiler errors
To: Henry Nelson <henry@irm.nara.kindai.ac.jp>
From: Todd Whitesel <toddpw@best.com>
List: netbsd-help
Date: 04/11/2001 01:01:08
> windows.c:151: warning: assignment makes pointer from integer without a cast
> ==>> tmpfiles[tmpfilex++] = stralloc(path);
You have not declared stralloc anywhere, or at least not before this code.
The C language says that the compiler must assume stralloc returns an int,
and the behavior of this code is implementation defined -- meaning it works
on many systems but is guaranteed to break on some others. For this, it will
tend to break on any system for which sizeof(char *) > sizeof(int).
I don't see stralloc in the NetBSD or Solaris /usr/include/*.h so I guess
it is your own function? You need a declaration like:
char *stralloc (char *);
... to appear early in any source file using stralloc -- typically this is
done by including a header file. For simple projects you can get away with
a single "myfuncs.h", but a more extensible method is to create a .h file
for each .c file that exports functions, and have the other files include
those headers as needed. (I do this in all my projects.)
This is a standard C portability issue. while you can often get away with
ignoring the warnings on an all 32-bit system, if you port your programs
to an Alpha or other 64-bit system that has 32-bit ints, you will most
likely lose and your programs will blow chunks. (This sort of code also
died on older 16-bit systems with long pointers, so it's not a new thing.)
>TLX.c:555: warning: `fa_xp' was declared implicitly `extern' and later `static'
>TLX.c:488: warning: previous declaration of `fa_xp'
> ==>> static fa_xp(ofsp,regexp,class)
> (the previous declaration was: "return fa_xp(fa_root,regexp,class);"
> (Actually, in the second case I've just been changing all those "static"s
> to "extern". It works as far as shutting the compiler up, but is it messing
> up the code? Should I be going the other direction?)
Yes. Putting extern on a function declaration is effectively redundant -- it
only means something real for a variable declaration.
All you have to do is put the line:
static int fa_xp (ofsp_type, regexp_type, class_type);
(Replace the _type's with the actualy types you use: int, struct foo, etc.)
... early in the file and outside of any functions. That will take care of it.
You must have been using a pretty permissive compiler before this... try
adding "-ansi -pedantic-errors -Wall -Werror" if you want some real fun.
Todd Whitesel
toddpw @ best.com