Mail Archives: djgpp/1998/02/05/03:55:02
>#include <stdio.h>
>
>// extern int Test (void);
>int x;
>
>main()
>{
> x = 1;
> x = Test();
> printf ("%i", x);
>}
>
>This works, but of course gives the implicit declaration warning. When
Does it then compile correctly? Or does it stop at link because ther is
no definition for function Test?
>I uncomment the extern statement, however, I get a SIGSEGV error,
Maybe there are problems because you prototype a function so the compiler
writes code according to it and then the call is to a different function
this can often cause problems like invalid address access and so on.
>which can be fixed by removing the parenthesis from the call to Test.
>I then get a warning that I need to type cast the procedure, and
>inevitably get 0 in x. I keep thinking there's a dumb mistake I've
You are doing something completely different from what you wanted:
if you "remove the parenthesis from the call" you are actually
*not calling* the function but instead you are assigning to x
a *pointer to the function* (the warning should then say "assigning
pointer to integer without a cast")
>overlooked, but can't find it. I've also installed RSXNTDJ, if that
>does anything funky to the compiler. Thanks for any help,
RSXNTDJ comes with a particular linker, which does not complain if
it does not find the definition of functions... this can explain
why you have a sigsegv: you want to call Test but the linker didn't
find it (I don't know assembler, maybe it is named _Test?) and
did not emit an error message for it. At run time you then crash.
ciao
Giacomo
- Raw text -