Subject: port-alpha/9056: C++ files can't #include
To: None <gnats-bugs@gnats.netbsd.org>
From: Dave Huang <khym@bga.com>
List: netbsd-bugs
Date: 12/26/1999 03:52:07
>Number:         9056
>Category:       port-alpha
>Synopsis:       C++ files can't #include <sys/param.h>
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-alpha-maintainer (NetBSD/alpha Portmaster)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 26 03:39:00 1999
>Last-Modified:
>Originator:     Dave Huang
>Organization:
Name: Dave Huang     |   Mammal, mammal / their names are called /
INet: khym@bga.com   |   they raise a paw / the bat, the cat /
FurryMUCK: Dahan     |   dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 24 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Release:        NetBSD-current as of December 25, 1999
>Environment:
	
System: NetBSD yerfable.metonymy.com 1.4P NetBSD 1.4P (YERFABLE) #57: Sun Dec 19 23:06:35 CST 1999 khym@yerfable.metonymy.com:/usr/src.local/sys/arch/alpha/compile/YERFABLE alpha


>Description:
On the alpha, /usr/include/sys/param.h includes a couple of headers
that have inlined functions (machine/alpha_cpu.h and
machine/atomic.h). They're K&R style function declarations though,
which C++ doesn't support, so any C++ file that includes that header
won't compile.
	
>How-To-Repeat:
% echo "#include <sys/param.h>" > gorp.c
% c++ -c gorp.c
In file included from /usr/include/machine/cpu.h:93,
                 from /usr/include/machine/param.h:54,
                 from /usr/include/sys/param.h:147,
                 from gorp.c:1:
/usr/include/machine/alpha_cpu.h:433: `ctx' was not declared in this scope
/usr/include/machine/alpha_cpu.h:434: syntax error before `unsigned'

>Fix:
Well, ANSIfying it would do the trick, but we seem to like to have a
semblance of K&R compatibility... So I guess doing the "#if __STDC__"
thing (like in sys/isofs/cd9660/iso.h) would work.

The files in sys/arch/alpha/include that have inline functions are:
alpha_cpu.h atomic.h bwx.h intr.h lock.h pmap.h. Of those, intr.h and
pmap.h's inline functions are inside an #ifdef _KERNEL, so I didn't
bother messing with them (I seem to remember seeing someone on one of
the lists mention that C++ code could be in the kernel... well if that
ever happens, someone can fix those header files :).  lock.h never
gets installed into /usr/include/machine, so I didn't do anything with
it either (but maybe it should be installed? /usr/include/sys/lock.h
will #include <machine/lock.h> if MULTIPROCESSOR is #defined).

So, here are patches for alpha_cpu.h, atomic.h, and bwx.h:

diff -ur /usr/src/sys/arch/alpha/include/alpha_cpu.h ./alpha_cpu.h
--- /usr/src/sys/arch/alpha/include/alpha_cpu.h	Fri Dec  3 06:09:42 1999
+++ ./alpha_cpu.h	Sun Dec 26 05:13:51 1999
@@ -430,8 +430,12 @@
 }
 
 static __inline unsigned long
+#if __STDC__
+alpha_pal_swpctx(unsigned long ctx)
+#else
 alpha_pal_swpctx(ctx)
 	unsigned long ctx;
+#endif
 {
 	register unsigned long a0 __asm("$16") = ctx;
 	register unsigned long v0 __asm("$0");
@@ -446,8 +450,12 @@
 }
 
 static __inline unsigned long
+#if __STDC__
+alpha_pal_swpipl(unsigned long ipl)
+#else
 alpha_pal_swpipl(ipl)
 	unsigned long ipl;
+#endif
 {
 	register unsigned long a0 __asm("$16") = ipl;
 	register unsigned long v0 __asm("$0");
@@ -462,9 +470,13 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_pal_tbi(unsigned long op, vaddr_t va)
+#else
 alpha_pal_tbi(op, va)
 	unsigned long op;
 	vaddr_t va;
+#endif
 {
 	register unsigned long a0 __asm("$16") = op;
 	register unsigned long a1 __asm("$17") = va;
@@ -491,8 +503,12 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_pal_wrfen(unsigned long onoff)
+#else
 alpha_pal_wrfen(onoff)
 	unsigned long onoff;
+#endif
 {
 	register unsigned long a0 __asm("$16") = onoff;
 
@@ -504,8 +520,12 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_pal_wripir(unsigned long cpu_id)
+#else
 alpha_pal_wripir(cpu_id)
 	unsigned long cpu_id;
+#endif
 {
 	register unsigned long a0 __asm("$16") = cpu_id;
 
@@ -517,8 +537,12 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_pal_wrusp(unsigned long usp)
+#else
 alpha_pal_wrusp(usp)
 	unsigned long usp;
+#endif
 {
 	register unsigned long a0 __asm("$16") = usp;
 
@@ -530,8 +554,12 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_pal_wrmces(unsigned long mces)
+#else
 alpha_pal_wrmces(mces)
 	unsigned long mces;
+#endif
 {
 	register unsigned long a0 __asm("$16") = mces;
 
@@ -543,8 +571,12 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_pal_wrval(unsigned long val)
+#else
 alpha_pal_wrval(val)
 	unsigned long val;
+#endif
 {
 	register unsigned long a0 __asm("$16") = val;
 
diff -ur /usr/src/sys/arch/alpha/include/atomic.h ./atomic.h
--- /usr/src/sys/arch/alpha/include/atomic.h	Fri Dec  3 06:09:42 1999
+++ ./atomic.h	Sun Dec 26 05:16:02 1999
@@ -64,9 +64,13 @@
  *	Atomically set bits in a quadword.
  */
 static __inline void
+#if __STDC__
+alpha_atomic_setbits_q(__volatile unsigned long *ulp, unsigned long v)
+#else
 alpha_atomic_setbits_q(ulp, v)
 	__volatile unsigned long *ulp;
 	unsigned long v;
+#endif
 {
 	unsigned long t0;
 
@@ -91,9 +95,13 @@
  *	Atomically clear bits in a quadword.
  */
 static __inline void
+#if __STDC__
+alpha_atomic_clearbits_q(__volatile unsigned long *ulp, unsigned long v)
+#else
 alpha_atomic_clearbits_q(ulp, v)
 	__volatile unsigned long *ulp;
 	unsigned long v;
+#endif
 {
 	unsigned long t0;
 
@@ -118,9 +126,13 @@
  *	Atomically add a value to a quadword.
  */
 static __inline void
+#if __STDC__
+alpha_atomic_add_q(__volatile unsigned long *ulp, unsigned long v)
+#else
 alpha_atomic_add_q(ulp, v)
 	__volatile unsigned long *ulp;
 	unsigned long v;
+#endif
 {
 	unsigned long t0;
 
@@ -145,9 +157,13 @@
  *	Atomically subtract a value from a quadword.
  */
 static __inline void
+#if __STDC__
+alpha_atomic_sub_q(__volatile unsigned long *ulp, unsigned long v)
+#else
 alpha_atomic_sub_q(ulp, v)
 	__volatile unsigned long *ulp;
 	unsigned long v;
+#endif
 {
 	unsigned long t0;
 
@@ -172,9 +188,13 @@
  *	Atomically load and latch a quadword value.
  */
 static __inline unsigned long
+#if __STDC__
+alpha_atomic_loadlatch_q(__volatile unsigned long *ulp, unsigned long v)
+#else
 alpha_atomic_loadlatch_q(ulp, v)
 	__volatile unsigned long *ulp;
 	unsigned long v;
+#endif
 {
 	unsigned long t0, v0;
 
diff -ur /usr/src/sys/arch/alpha/include/bwx.h ./bwx.h
--- /usr/src/sys/arch/alpha/include/bwx.h	Thu Dec  2 13:41:40 1999
+++ ./bwx.h	Sun Dec 26 05:24:04 1999
@@ -62,8 +62,12 @@
 	__attribute__((__unused__));
 
 static __inline u_int8_t
+#if __STDC__
+alpha_ldbu(__volatile u_int8_t *a0)
+#else
 alpha_ldbu(a0)
 	__volatile u_int8_t *a0;
+#endif
 {
 	u_int8_t v0;
 
@@ -75,8 +79,12 @@
 }
 
 static __inline u_int16_t
+#if __STDC__
+alpha_ldwu(__volatile u_int16_t *a0)
+#else
 alpha_ldwu(a0)
 	__volatile u_int16_t *a0;
+#endif
 {
 	u_int16_t v0;
 
@@ -88,9 +96,13 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_stb(__volatile u_int8_t *a0, u_int8_t a1)
+#else
 alpha_stb(a0, a1)
 	__volatile u_int8_t *a0;
 	u_int8_t a1;
+#endif
 {
 
 	__asm __volatile("stb %1, %0"
@@ -99,9 +111,13 @@
 }
 
 static __inline void
+#if __STDC__
+alpha_stw(__volatile u_int16_t *a0, u_int16_t a1)
+#else
 alpha_stw(a0, a1)
 	__volatile u_int16_t *a0;
 	u_int16_t a1;
+#endif
 {
 
 	__asm __volatile("stw %1, %0"
@@ -110,8 +126,12 @@
 }
 
 static __inline u_int8_t
+#if __STDC__
+alpha_sextb(u_int8_t a0)
+#else
 alpha_sextb(a0)
 	u_int8_t a0;
+#endif
 {
 	u_int8_t v0;
 
@@ -123,8 +143,12 @@
 }
 
 static __inline u_int16_t
+#if __STDC__
+alpha_sextw(u_int16_t a0)
+#else
 alpha_sextw(a0)
 	u_int16_t a0;
+#endif
 {
 	u_int16_t v0;
 

>Audit-Trail:
>Unformatted: