Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* gcc question
@ 1996-06-03 21:13 Brian Wood
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Wood @ 1996-06-03 21:13 UTC (permalink / raw)


OK gcc gurus (defined as: anyone who knows more than me, which is just
about everybody): 

Here's my problem:

I am trying to compile mgetty on my UDB, running kernel 1.3.89 and
using gcc version 2.7.2. This setup has successfully compiled dozens
of other programs with little or no trouble.

Everything goes along swimingly until it tries to compile conf_mg.c.
I get several warnings like:

warning: initializer element for c.port_owner.d.l is not computable
at load time

After several of these errors (the filename is different in each of course)
I get

make *** [conf_mg.o] error 1

The code which is apparently causing the trouble is an "initialized union"
and looks like this:

struct conf_data_mgetty c = {
	{ "speed", DEFAULT_PORTSPEED, CT_INT, C_PRESET },
	
		(SEVERAL SIMILAR LINES)

	{ "port-owner", (int) DEVICE_OWNER, CT_STRING, C_PRESET },	

		(SEVERAL SIMILAR LINES)

Of the dozens of lines in this structure, only the ones containing C_PRESET
seem to be causing trouble. I have consulted with the author, and he says
these lines have in common the fact that they are performing a conversion

"char *" (string) -> "int"

which should work, but he admits the code is "on the edge" and might have
problems on some platforms.

The program compiles just fine on my pentium system (gcc 2.6.3)

So, does anyone have any ideas how I might get this code to compile?
The program is very useful and I would hate to have to give it up.

Anyone have any ideas as to what might be "different" about the
Alpha version of gcc and thus cause this problem?

I would very much appreciate any suggestions which might get me pointed
in the right direction.

Thanks,

Brian E.W. Wood
beww@intac.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc question
@ 1996-06-03 22:21 David Mosberger-Tang
  0 siblings, 0 replies; 5+ messages in thread
From: David Mosberger-Tang @ 1996-06-03 22:21 UTC (permalink / raw)


Here is a patch that will make mgetty+sendfax-0.98 as found on sunsite
compile under Linux/Alpha.

Please note that it is _not possible_ to initialize unions in ANSI C.
And there are good reasons why this is so: mgetty fails to compile
under Linux/Alpha because there a pointer is 64 bits wide whereas an
int is only 32 bits wide.  The patch below makes use of a GNU C
extension.  With the patch, mgetty will compile as long as GCC is
used.  However, it would be better to initialize the variants at
runtime, since that would make the program more portable.

	--david

--
diff -urN mgetty-0.98/conf_mg.c mgetty-0.98axp/conf_mg.c
--- mgetty-0.98/conf_mg.c	Wed Aug 30 03:42:16 1995
+++ mgetty-0.98axp/conf_mg.c	Mon Jun  3 15:11:13 1996
@@ -53,68 +53,69 @@
  */
 
 struct conf_data_mgetty c = {
-	{ "speed", DEFAULT_PORTSPEED, CT_INT, C_PRESET },
-	{ "switchbd", FAX_RECV_SWITCHBD, CT_INT, C_PRESET },
-	{ "direct", FALSE, CT_BOOL, C_PRESET },
-	{ "blocking", FALSE, CT_BOOL, C_PRESET },
+	{ "speed", {DEFAULT_PORTSPEED}, CT_INT, C_PRESET },
+	{ "switchbd", {FAX_RECV_SWITCHBD}, CT_INT, C_PRESET },
+	{ "direct", {FALSE}, CT_BOOL, C_PRESET },
+	{ "blocking", {FALSE}, CT_BOOL, C_PRESET },
 
-	{ "port-owner", (int) DEVICE_OWNER, CT_STRING, C_PRESET },
+	{ "port-owner", {p: DEVICE_OWNER}, CT_STRING, C_PRESET },
 #ifdef DEVICE_GROUP
-	{ "port-group", (int) DEVICE_GROUP, CT_STRING, C_PRESET },
+	{ "port-group", {p: DEVICE_GROUP}, CT_STRING, C_PRESET },
 #else
-	{ "port-group", 0, CT_STRING, C_EMPTY },
+	{ "port-group", {p: 0}, CT_STRING, C_EMPTY },
 #endif
-	{ "port-mode", FILE_MODE, CT_INT, C_PRESET },
+	{ "port-mode", {FILE_MODE}, CT_INT, C_PRESET },
 
-	{ "toggle-dtr", TRUE, CT_BOOL, C_PRESET },
-	{ "toggle-dtr-waittime", 500, CT_INT, C_PRESET },
-	{ "data-only", FALSE, CT_BOOL, C_PRESET },
-	{ "fax-only", FALSE, CT_BOOL, C_PRESET },
-	{ "modem-type", (int) DEFAULT_MODEMTYPE, CT_STRING, C_PRESET },
-	{ "init-chat", 0, CT_CHAT, C_EMPTY },
-
-	{ "modem-check-time", MODEM_CHECK_TIME, CT_INT, C_PRESET },
-	{ "rings", 1, CT_INT, C_PRESET },
-	{ "get-cnd-chat", 0, CT_CHAT, C_EMPTY },
-	{ "answer-chat", 0, CT_CHAT, C_EMPTY },
-	{ "answer-chat-timeout", 80, CT_INT, C_PRESET },
-	{ "autobauding", FALSE, CT_BOOL, C_PRESET },
-
-	{ "ringback", FALSE, CT_BOOL, C_PRESET },
-	{ "ringback-time", 30, CT_INT, C_PRESET },
-
-	{ "issue-file", (int)"/etc/issue", CT_STRING, C_PRESET },
-	{ "prompt-waittime", 500, CT_INT, C_PRESET },
-	{ "login-prompt", (int) LOGIN_PROMPT, CT_STRING, C_PRESET },
+	{ "toggle-dtr", {TRUE}, CT_BOOL, C_PRESET },
+	{ "toggle-dtr-waittime", {500}, CT_INT, C_PRESET },
+	{ "data-only", {FALSE}, CT_BOOL, C_PRESET },
+	{ "fax-only", {FALSE}, CT_BOOL, C_PRESET },
+	{ "modem-type", {p: DEFAULT_MODEMTYPE}, CT_STRING, C_PRESET },
+	{ "init-chat", {0}, CT_CHAT, C_EMPTY },
+
+	{ "modem-check-time", {MODEM_CHECK_TIME}, CT_INT, C_PRESET },
+	{ "rings", {1}, CT_INT, C_PRESET },
+	{ "get-cnd-chat", {0}, CT_CHAT, C_EMPTY },
+	{ "answer-chat", {0}, CT_CHAT, C_EMPTY },
+	{ "answer-chat-timeout", {80}, CT_INT, C_PRESET },
+	{ "autobauding", {FALSE}, CT_BOOL, C_PRESET },
+
+	{ "ringback", {FALSE}, CT_BOOL, C_PRESET },
+	{ "ringback-time", {30}, CT_INT, C_PRESET },
+
+	{ "issue-file", {p: "/etc/issue"}, CT_STRING, C_PRESET },
+	{ "prompt-waittime", {500}, CT_INT, C_PRESET },
+	{ "login-prompt", {p: LOGIN_PROMPT}, CT_STRING, C_PRESET },
 #ifdef MAX_LOGIN_TIME			/*!!! hmmm? */
-	{ "login-time", MAX_LOGIN_TIME, CT_INT, C_PRESET },
+	{ "login-time", {MAX_LOGIN_TIME}, CT_INT, C_PRESET },
 #else
-	{ "login-time", 0, CT_INT, C_EMPTY },
+	{ "login-time", {0}, CT_INT, C_EMPTY },
 #endif
-	{ "fax-id", (int)FAX_STATION_ID, CT_STRING, C_PRESET },
-	{ "fax-server-file", 0, CT_STRING, C_EMPTY },
-	{ "diskspace", MINFREESPACE, CT_INT, C_PRESET },
+	{ "fax-id", {p: FAX_STATION_ID}, CT_STRING, C_PRESET },
+	{ "fax-server-file", {0}, CT_STRING, C_EMPTY },
+	{ "diskspace", {MINFREESPACE}, CT_INT, C_PRESET },
 #ifdef MAIL_TO
-	{ "notify", (int)MAIL_TO, CT_STRING, C_PRESET },
+	{ "notify", {p: MAIL_TO}, CT_STRING, C_PRESET },
 #else
-	{ "notify", 0, CT_STRING, C_EMPTY },
+	{ "notify", {p: 0}, {CT_STRING}, C_EMPTY },
 #endif
-	{ "fax-owner", (int)FAX_IN_OWNER, CT_STRING, C_PRESET },
+	{ "fax-owner", {p: FAX_IN_OWNER}, CT_STRING, C_PRESET },
 #ifdef FAX_IN_GROUP
-	{ "fax-group", (int)FAX_IN_GROUP, CT_STRING, C_PRESET },
+	{ "fax-group", {p: FAX_IN_GROUP}, CT_STRING, C_PRESET },
 #else
-	{ "fax-group", 0, CT_STRING, C_EMPTY },
+	{ "fax-group", {p: 0}, CT_STRING, C_EMPTY },
 #endif
-	{ "fax-mode", FAX_FILE_MODE, CT_INT, C_PRESET },
+	{ "fax-mode", {FAX_FILE_MODE}, CT_INT, C_PRESET },
 
-	{ "debug", LOG_LEVEL, CT_INT, C_PRESET },
+	{ "debug", {LOG_LEVEL}, CT_INT, C_PRESET },
 	
-	{ "statistics-chat", 0, CT_CHAT, C_EMPTY },
-	{ "statistics-file", 0, CT_STRING, C_EMPTY },
-	{ "gettydefs", (int)GETTYDEFS_DEFAULT_TAG, CT_STRING, C_PRESET },
-	{ "term", 0, CT_STRING, C_EMPTY },
+	{ "statistics-chat", {0}, CT_CHAT, C_EMPTY },
+	{ "statistics-file", {0}, CT_STRING, C_EMPTY },
+	{ "gettydefs", {p: GETTYDEFS_DEFAULT_TAG}, CT_STRING, C_PRESET },
+	{ "term", {0}, CT_STRING, C_EMPTY },
 
-	{ NULL, 0, CT_STRING, C_EMPTY }};
+	{ NULL, {0}, CT_STRING, C_EMPTY }
+};
 
 /*
  *	exit_usage() - exit with usage display
diff -urN mgetty-0.98/conf_sf.c mgetty-0.98axp/conf_sf.c
--- mgetty-0.98/conf_sf.c	Wed Aug 30 03:42:18 1995
+++ mgetty-0.98axp/conf_sf.c	Mon Jun  3 15:13:09 1996
@@ -25,29 +25,29 @@
 #endif
 
 struct conf_data_sendfax c = {
-	{ "fax-devices", 0, CT_STRING, C_EMPTY },
-	{ "fax-devices", 0, CT_STRING, C_IGNORE },
-	{ "modem-init", 0, CT_STRING, C_EMPTY },
+	{ "fax-devices", {0}, CT_STRING, C_EMPTY },
+	{ "fax-devices", {0}, CT_STRING, C_IGNORE },
+	{ "modem-init", {0}, CT_STRING, C_EMPTY },
 #ifdef FAX_MODEM_HANDSHAKE
-	{ "modem-handshake", (int) FAX_MODEM_HANDSHAKE, CT_STRING, C_PRESET },
+	{ "modem-handshake", {p:FAX_MODEM_HANDSHAKE}, CT_STRING, C_PRESET },
 #else
-	{ "modem-handshake", 0, CT_STRING, C_EMPTY },
+	{ "modem-handshake", {p:0}, CT_STRING, C_EMPTY },
 #endif
-	{ "modem-type", (int) DEFAULT_MODEMTYPE, CT_STRING, C_PRESET },
-	{ "max-tries", FAX_SEND_MAX_TRIES, CT_INT, C_PRESET },
-	{ "max-tries-continue", TRUE, CT_BOOL, C_PRESET },
-	{ "speed", FAX_SEND_BAUD, CT_INT, C_PRESET },
-	{ "switchbd", FAX_SEND_SWITCHBD, CT_INT, C_PRESET },
-	{ "dial-prefix", (int) FAX_DIAL_PREFIX, CT_STRING, C_PRESET },
-	{ "fax-id", (int)FAX_STATION_ID, CT_STRING, C_PRESET },
-	{ "poll-dir", (int)".", CT_STRING, C_PRESET },
-	{ "normal-res", 0, CT_BOOL, C_PRESET },
-	{ "debug", LOG_LEVEL, CT_INT, C_PRESET },
-	{ "verbose", FALSE, CT_BOOL, C_PRESET },
-	{ "" /* polling */, FALSE, CT_BOOL, C_PRESET },
-	{ "page-header", 0, CT_STRING, C_EMPTY },
-	{ "" /* stdin */, FALSE, CT_BOOL, C_PRESET },
-	{ NULL, 0, CT_STRING, C_EMPTY }};
+	{ "modem-type", {p:DEFAULT_MODEMTYPE}, CT_STRING, C_PRESET },
+	{ "max-tries", {FAX_SEND_MAX_TRIES}, CT_INT, C_PRESET },
+	{ "max-tries-continue", {TRUE}, CT_BOOL, C_PRESET },
+	{ "speed", {FAX_SEND_BAUD}, CT_INT, C_PRESET },
+	{ "switchbd", {FAX_SEND_SWITCHBD}, CT_INT, C_PRESET },
+	{ "dial-prefix", {p:FAX_DIAL_PREFIX}, CT_STRING, C_PRESET },
+	{ "fax-id", {p:FAX_STATION_ID}, CT_STRING, C_PRESET },
+	{ "poll-dir", {p:"."}, CT_STRING, C_PRESET },
+	{ "normal-res", {0}, CT_BOOL, C_PRESET },
+	{ "debug", {LOG_LEVEL}, CT_INT, C_PRESET },
+	{ "verbose", {FALSE}, CT_BOOL, C_PRESET },
+	{ "" /* polling */, {FALSE}, CT_BOOL, C_PRESET },
+	{ "page-header", {0}, CT_STRING, C_EMPTY },
+	{ "" /* stdin */, {FALSE}, CT_BOOL, C_PRESET },
+	{ NULL, {0}, CT_STRING, C_EMPTY }};
 
 int sendfax_parse_args _P2( (argc,argv), int argc, char ** argv )
 {
diff -urN mgetty-0.98/config.c mgetty-0.98axp/config.c
--- mgetty-0.98/config.c	Wed Aug 30 03:42:12 1995
+++ mgetty-0.98axp/config.c	Mon Jun  3 14:54:50 1996
@@ -8,13 +8,11 @@
  * Read and parse config file(s), see conf_*.[ch] for example use
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include "syslibs.h"
 #include <ctype.h>
 #include <string.h>
-#ifndef ENOENT
-#include <errno.h>
-#endif
 
 #include "mgetty.h"
 #include "config.h"
diff -urN mgetty-0.98/do_chat.c mgetty-0.98axp/do_chat.c
--- mgetty-0.98/do_chat.c	Wed Aug 30 03:41:30 1995
+++ mgetty-0.98axp/do_chat.c	Mon Jun  3 14:53:41 1996
@@ -5,6 +5,7 @@
  * This module handles all the non-fax talk with the modem
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include "syslibs.h"
 #include <unistd.h>
diff -urN mgetty-0.98/logname.c mgetty-0.98axp/logname.c
--- mgetty-0.98/logname.c	Wed Aug 30 03:41:58 1995
+++ mgetty-0.98axp/logname.c	Mon Jun  3 14:54:02 1996
@@ -1,5 +1,6 @@
 #ident "@(#)logname.c	3.1 95/08/30 Copyright (c) Gert Doering"
 
+#include <errno.h>
 #include <stdio.h>
 #include "syslibs.h"
 #include <unistd.h>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc question
       [not found] <199606032221.PAA15714@koala.azstarnet.com>
@ 1996-06-04  7:46 ` Linus Torvalds
  0 siblings, 0 replies; 5+ messages in thread
From: Linus Torvalds @ 1996-06-04  7:46 UTC (permalink / raw)


On Mon, 3 Jun 1996, David Mosberger-Tang wrote:
> 
> Please note that it is _not possible_ to initialize unions in ANSI C.

Actually, it's possible (umm - raincheck on the standard here, I'm too 
lazy to look it up, but I'm fairly certain). The standard allows you to 
initialize unions, but only the _first_ entry in a union.

> And there are good reasons why this is so: mgetty fails to compile
> under Linux/Alpha because there a pointer is 64 bits wide whereas an
> int is only 32 bits wide.  The patch below makes use of a GNU C
> extension.  With the patch, mgetty will compile as long as GCC is
> used.  However, it would be better to initialize the variants at
> runtime, since that would make the program more portable.

Another possibility is to put the largest entity first (the pointer), and 
then always initialize even the integers as pointers (rather than 
initializing the pointers as integers). That will then work on 
little-endian machines like the alpha (and will work on any big-endian 
machines where the sizes match, of course, taking care of most of them)...

A third possibility is to use "long" instead of "int" in the union, and casts
to (long) instead of (int) to initialize the entries. That's probably just
about as portable as this is going to get. I agree with David that the right
way to do this is to do the init at run-time, but that is often fraught with
other problems. Maybe an updated C standard will make the gcc extension a 
standard feature some day.

Using a gcc-specific feature may be the best thing to do in this case, 
but if somebody wants to use DEC cc without hacking the code to death, 
I'd just suggest using the "long" approach.

		Linus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc question
       [not found] <Pine.LNX.3.91.960604103638.1696H-100000@linux.cs.Helsinki.FI>
@ 1996-06-04 12:22 ` Michael K. Johnson
  0 siblings, 0 replies; 5+ messages in thread
From: Michael K. Johnson @ 1996-06-04 12:22 UTC (permalink / raw)


Linus Torvalds writes:
>On Mon, 3 Jun 1996, David Mosberger-Tang wrote:
>> Please note that it is _not possible_ to initialize unions in ANSI C.
>
>Actually, it's possible (umm - raincheck on the standard here, I'm too 
>lazy to look it up, but I'm fairly certain). The standard allows you to 
>initialize unions, but only the _first_ entry in a union.

Absolutely right.  Cancel the raincheck, Linus.

Just in case anyone wants standards support, see 6.5.7.  It says
"A brace-enclosed initializer for a union object initializes the
member that appears first in the declaration list of the union
type."

michaelkjohnson

"Ever wonder why the SAME PEOPLE make up ALL the conspiracy theories?"

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: gcc question
@ 1996-06-04 14:50 David Mosberger-Tang
  0 siblings, 0 replies; 5+ messages in thread
From: David Mosberger-Tang @ 1996-06-04 14:50 UTC (permalink / raw)


>>>>> On Tue, 04 Jun 1996 08:22:26 -0400, "Michael K. Johnson" <johnsonm@nigel.vnet.net> said:

  Michael> Linus Torvalds writes:
  >> On Mon, 3 Jun 1996, David Mosberger-Tang wrote:
  >>> Please note that it is _not possible_ to initialize unions in
  >>> ANSI C.
  >>  Actually, it's possible (umm - raincheck on the standard here,
  >> I'm too lazy to look it up, but I'm fairly certain). The standard
  >> allows you to initialize unions, but only the _first_ entry in a
  >> union.

  Michael> Absolutely right.  Cancel the raincheck, Linus.

  Michael> Just in case anyone wants standards support, see 6.5.7.  It
  Michael> says "A brace-enclosed initializer for a union object
  Michael> initializes the member that appears first in the
  Michael> declaration list of the union type."

Yes, you're both right.  I have an old C book which claims otherwise,
but checking a more recent one does indeed say that a union
initializer initializes the first member.  Sorry about the confusion.

	--david

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1996-06-04 14:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-06-04 14:50 gcc question David Mosberger-Tang
     [not found] <Pine.LNX.3.91.960604103638.1696H-100000@linux.cs.Helsinki.FI>
1996-06-04 12:22 ` Michael K. Johnson
     [not found] <199606032221.PAA15714@koala.azstarnet.com>
1996-06-04  7:46 ` Linus Torvalds
  -- strict thread matches above, loose matches on Subject: below --
1996-06-03 22:21 David Mosberger-Tang
1996-06-03 21:13 Brian Wood

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox