error: implicit declaration of function 'dap_main' is invalid in C99

Ryan Schmidt <[email protected]> Wed, 6 Jan 2021 09:07:36 -0600
Newsgroups gmane.comp.statistics.dap.bugs
Message-ID <[email protected]>
--Apple-Mail=_ACB2B466-337D-426F-A850-711BE0E7E3D0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

Hi, I'm a developer with MacPorts where we have a port for dap 3.10, but =
it does not build on macOS with the version of clang included with Xcode =
12 or later. The errors are:

dap0.c:241:3: error: implicit declaration of function 'dap_main' is =
invalid in C99 [-Werror,-Wimplicit-function-declaration]
ps1.c:904:29: error: implicit declaration of function 'dap_il' is =
invalid in C99 [-Werror,-Wimplicit-function-declaration]
ps1.c:905:29: error: implicit declaration of function 'dap_sl' is =
invalid in C99 [-Werror,-Wimplicit-function-declaration]
ps1.c:906:30: error: implicit declaration of function 'dap_dl' is =
invalid in C99 [-Werror,-Wimplicit-function-declaration]
sbstrans.c:214:7: error: implicit declaration of function 'unget1c' is =
invalid in C99 [-Werror,-Wimplicit-function-declaration]
sbstrans.c:1268:5: error: implicit declaration of function 'importtrans' =
is invalid in C99 [-Werror,-Wimplicit-function-declaration]
sbstrans.c:1270:5: error: implicit declaration of function =
'surveyselecttrans' is invalid in C99 =
[-Werror,-Wimplicit-function-declaration]

This was reported to MacPorts here:

https://trac.macports.org/ticket/61965

Apple deliberately changed implicit declaration of functions from a =
warning to an error in Xcode 12 because Apple introduced Macs using ARM =
processors. ARM processors use different calling conventions for =
variadic and non-variadic functions so the compiler must know before you =
call a function what kind of function it is. Prior to this becoming an =
error, if it did not know, it would guess, and if it guessed wrong, your =
program would crash.

Your INSTALL file even mentions that this problem will occur:

> Note: when DAP_HOME/src/dap.c
> compiles, you will get a warning:
>=20
> 	implicit declaration of function `strcat'
>=20
> and when DAP_HOME/src/dap0.c compiles, you will get a warning:
>=20
> 	implicit declaration of function `dap_main'
>=20
> Ignore these warnings.

Now that in Xcode 12 these are errors, not warnings, they cannot be =
ignored.

I am not familiar with dap, but the attached patch is what I have =
committed to MacPorts to address this problem. Hopefully you will agree =
that this was the correct fix and you can commit it to your repository. =
I'm also attaching my attempt at updating the INSTALL file for this and =
some other changes.


--Apple-Mail=_ACB2B466-337D-426F-A850-711BE0E7E3D0
Content-Disposition: attachment;
	filename=implicit.patch
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="implicit.patch"
Content-Transfer-Encoding: 7bit

Fix:

dap0.c:241:3: error: implicit declaration of function 'dap_main' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ps1.c:904:29: error: implicit declaration of function 'dap_il' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ps1.c:905:29: error: implicit declaration of function 'dap_sl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
ps1.c:906:30: error: implicit declaration of function 'dap_dl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
sbstrans.c:214:7: error: implicit declaration of function 'unget1c' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
sbstrans.c:1268:5: error: implicit declaration of function 'importtrans' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
sbstrans.c:1270:5: error: implicit declaration of function 'surveyselecttrans' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
--- src/dap0.c.orig	2014-04-16 13:36:34.000000000 -0500
+++ src/dap0.c	2021-01-06 08:45:53.000000000 -0600
@@ -91,6 +91,8 @@
 static int nmallocs = 0;
 static int nfrees = 0;
 
+extern int dap_main(int argc, char **argv);
+
 char *dap_malloc(int nbytes, char *mesg)
 {
   char *m;
--- src/ps1.c.orig	2014-04-16 13:36:34.000000000 -0500
+++ src/ps1.c	2021-01-06 08:41:30.000000000 -0600
@@ -34,6 +34,9 @@
 extern dataobs dap_obs[];
 extern FILE *dap_err;
 
+extern void dap_dl(char varname[], double *dbl);
+extern void dap_il(char varname[], int *i);
+extern void dap_sl(char varname[], char *s);
 extern char *pict_newstr(char *str);
 
 void pict_maketick(tick *t, double num, char *label, double len)
--- src/sbstrans.c.orig	2014-04-16 13:36:34.000000000 -0500
+++ src/sbstrans.c	2021-01-06 08:44:04.000000000 -0600
@@ -53,6 +53,10 @@
   ""
 };
 
+extern void importtrans(char *step, FILE *dapfile);
+extern void surveyselecttrans(char *step, FILE *dapfile);
+extern void unget1c(int c, FILE *dotc, FILE *dapc);
+
 int iskeyword(char *str)
 {
   int k;

--Apple-Mail=_ACB2B466-337D-426F-A850-711BE0E7E3D0
Content-Disposition: attachment;
	filename=INSTALL.patch
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="INSTALL.patch"
Content-Transfer-Encoding: 7bit

--- INSTALL.orig	2014-04-16 13:36:34.000000000 -0500
+++ INSTALL	2021-01-06 09:01:11.000000000 -0600
@@ -22,33 +22,22 @@
 
 COMPILATION
 
-Choose a place to install dap and its documentation.  Let's call this
+Choose a place to extract dap and its documentation.  Let's call this
 place `DAP_HOME'.  Untar the source code.  This should create directories
-`src', `doc', and `examples'.  
+`src', `doc', and `examples'.
 
 If you want the executables, includes, library, and info files installed
-in subdirectories `bin', `include', `lib', and `info', respectively, of
-`/usr/local', then simply issue the following commands:
+in subdirectories `bin', `include', `lib', and `share/info', respectively,
+of `/usr/local', then simply issue the following commands:
 
 	./configure
 	make
-        make install
-
-Otherwise, edit `Makefile.in' to select a different place to install
-and then type the above commands. Note: when DAP_HOME/src/dap.c
-compiles, you will get a warning:
-
-	implicit declaration of function `strcat'
-
-and when DAP_HOME/src/dap0.c compiles, you will get a warning:
-
-	implicit declaration of function `dap_main'
-
-Ignore these warnings.  Now rehash.  
-
-With new updates (version 3.8)  the above warnings may not occur.
+	sudo make install
 
+To install elsewhere, use e.g. --prefix=/opt/dap when invoking ./configure
+or consult ./configure --help for more options.
 
+After installing, rehash.
 
 ENVIRONMENT
 
@@ -76,12 +65,12 @@
 
 READING THE MANUAL
 
-To read the manual in info, you will need to have `/usr/local/info' (or
-whatever directory you installed the info file in) in your `INFOPATH'.
+To read the manual in info, you will need to have `/usr/local/share/info'
+(or whatever directory you installed the info file in) in your `INFOPATH'.
 The following command (which you will probably want to put in your
-shell's `rc' file) will do that:
+shell's `rc' file) will do that (if your shell derives from C shell):
 
-	setenv INFOPATH ".:/usr/info:/usr/local/info"
+	setenv INFOPATH ".:/usr/share/info:/usr/local/share/info"
 
 Then issue the command:
 

--Apple-Mail=_ACB2B466-337D-426F-A850-711BE0E7E3D0--