www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/05/03:55:02

From: G DOT DegliEsposti AT ads DOT it
To: djgpp AT delorie DOT com
Message-ID: <C12565A2.0030046A.00@vega.ads.it>
Date: Thu, 5 Feb 1998 09:52:41 +0100
Subject: Re: Declaring external assembly procedures
Mime-Version: 1.0




>#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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019