--- In wrote:
> >function. If I put all my source code into one big module it worked
> >fine.
>
> The thing that seems odd to me is that it "worked fine". If you
> compile this program:
>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <unistd.h>
>
> int stat;
>
> main()
> {
> struct stat b;
> stat("file",&b);
> }
>
> don't you get errors like
> c.c:5: `stat' redeclared as different kind of symbol
> /usr/include/sys/stat.h:358: previous declaration of `stat'
> c.c: In function `main':
> c.c:10: called object is not a function
> ?
>
You're absolutely right, Mark. I mis-spoke when I said it "worked
just fine." It only compiled AFTER I got the above error and changed
the name of my variable "stat" to something else. Where it failed to
catch the error was when I had declared the variable "stat" in a
different module as shown below. The compiler/linker doesn't flag an
error in this case and the program crashes. It was sloppy
programming on my part and I should have seen what was going on much
sooner (right now I'm hitting myself on the head and saying "Stupid,
stupid, stupid!"). I plan to take all the advice that has been given
here. I've already implemented the global include file idea.
Thanks very much to everyone who responded. You've all been very helpful.
Ed
THIS CODE COMPILES AND LINKS BUT GIVES A SEGMENTATION FAULT WHEN RUN:
// ---------------------
// stat_a.c
// ---------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
void some_function (void);
main()
{
struct stat b;
stat("file",&b);
some_function();
}
// ---------------------
// stat_b.c
// ---------------------
#include <unistd.h>
#include <stdio.h>
int stat;
void some_function (void)
{
printf("Do something\n");
}
Compiled with:
$> gcc -g -Wall -o /bin/mystat stat_a.c stat_b.c
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|