[news.software.b] C news on System V/AT

philip@axis.fr (Philip Peake) (07/12/89)

Trying to compile the file relay/hdrdefs.c on Microport System V/AT
produces complaints from the compiler, about too complex expressions.

For those who want to run C news on their Microport system (and I reccommend
it - its much less load and faster), the following is a really dirty
fix to the problem.

The problem is the offset() macro, which calculates the offset of a structure
member *at compile time*, and uses it to initialise another structure
member.

If you know how structures are stored on your machine, you can simply
calculate the offsets yourself, and write them directly into the code
(ugh ! - but no more ugh than letting the compiler do this dirty trick
for you in the first place !).

For Microport 286 systems, compiling in small model (ie NO -Ml flag),
the following patch will allow you to compile C news.

(You will need to hack 'spacefor' a little too)


*** hdrdefs.c.orig	Wed Jul 12 16:10:36 1989
--- hdrdefs.c	Wed Jul 12 16:10:28 1989
***************
*** 46,52
  static const char illobjnm[] = "Illegal-Object:";	/* zmailer bitching */
  
  static const struct hdrdef msghdr = {
! 	msgnm, STRLEN(msgnm), offsetof(struct headers, h_msgid) };
  static const struct hdrdef ngshdr = {
  	ngsnm, STRLEN(ngsnm), offsetof(struct headers, h_ngs) };
  const struct hdrdef pathhdr = {

--- 46,52 -----
  static const char illobjnm[] = "Illegal-Object:";	/* zmailer bitching */
  
  static const struct hdrdef msghdr = {
! 	msgnm, STRLEN(msgnm), 10 };
  static const struct hdrdef ngshdr = {
  	ngsnm, STRLEN(ngsnm), 2 };
  const struct hdrdef pathhdr = {
***************
*** 48,54
  static const struct hdrdef msghdr = {
  	msgnm, STRLEN(msgnm), offsetof(struct headers, h_msgid) };
  static const struct hdrdef ngshdr = {
! 	ngsnm, STRLEN(ngsnm), offsetof(struct headers, h_ngs) };
  const struct hdrdef pathhdr = {
  	pathnm, STRLEN(pathnm), offsetof(struct headers, h_path) };
  static const struct hdrdef subjhdr = {

--- 48,54 -----
  static const struct hdrdef msghdr = {
  	msgnm, STRLEN(msgnm), 10 };
  static const struct hdrdef ngshdr = {
! 	ngsnm, STRLEN(ngsnm), 2 };
  const struct hdrdef pathhdr = {
  	pathnm, STRLEN(pathnm), 16 };
  static const struct hdrdef subjhdr = {
***************
*** 50,56
  static const struct hdrdef ngshdr = {
  	ngsnm, STRLEN(ngsnm), offsetof(struct headers, h_ngs) };
  const struct hdrdef pathhdr = {
! 	pathnm, STRLEN(pathnm), offsetof(struct headers, h_path) };
  static const struct hdrdef subjhdr = {
  	subjnm, STRLEN(subjnm), offsetof(struct headers, h_subj) };
  

--- 50,56 -----
  static const struct hdrdef ngshdr = {
  	ngsnm, STRLEN(ngsnm), 2 };
  const struct hdrdef pathhdr = {
! 	pathnm, STRLEN(pathnm), 16 };
  static const struct hdrdef subjhdr = {
  	subjnm, STRLEN(subjnm), 0 };
  
***************
*** 52,58
  const struct hdrdef pathhdr = {
  	pathnm, STRLEN(pathnm), offsetof(struct headers, h_path) };
  static const struct hdrdef subjhdr = {
! 	subjnm, STRLEN(subjnm), offsetof(struct headers, h_subj) };
  
  static const struct hdrdef apphdr = {
  	appnm, STRLEN(appnm), offsetof(struct headers, h_approved) };

--- 52,58 -----
  const struct hdrdef pathhdr = {
  	pathnm, STRLEN(pathnm), 16 };
  static const struct hdrdef subjhdr = {
! 	subjnm, STRLEN(subjnm), 0 };
  
  static const struct hdrdef apphdr = {
  	appnm, STRLEN(appnm), 8 };
***************
*** 55,61
  	subjnm, STRLEN(subjnm), offsetof(struct headers, h_subj) };
  
  static const struct hdrdef apphdr = {
! 	appnm, STRLEN(appnm), offsetof(struct headers, h_approved) };
  static const struct hdrdef ctlhdr = {
  	ctlnm, STRLEN(ctlnm), offsetof(struct headers, h_ctlcmd) };
  static const struct hdrdef exphdr = {

--- 55,61 -----
  	subjnm, STRLEN(subjnm), 0 };
  
  static const struct hdrdef apphdr = {
! 	appnm, STRLEN(appnm), 8 };
  static const struct hdrdef ctlhdr = {
  	ctlnm, STRLEN(ctlnm), 6 };
  static const struct hdrdef exphdr = {
***************
*** 57,63
  static const struct hdrdef apphdr = {
  	appnm, STRLEN(appnm), offsetof(struct headers, h_approved) };
  static const struct hdrdef ctlhdr = {
! 	ctlnm, STRLEN(ctlnm), offsetof(struct headers, h_ctlcmd) };
  static const struct hdrdef exphdr = {
  	expnm, STRLEN(expnm), offsetof(struct headers, h_expiry) };
  static const struct hdrdef distrhdr = {

--- 57,63 -----
  static const struct hdrdef apphdr = {
  	appnm, STRLEN(appnm), 8 };
  static const struct hdrdef ctlhdr = {
! 	ctlnm, STRLEN(ctlnm), 6 };
  static const struct hdrdef exphdr = {
  	expnm, STRLEN(expnm), 14 };
  static const struct hdrdef distrhdr = {
***************
*** 59,65
  static const struct hdrdef ctlhdr = {
  	ctlnm, STRLEN(ctlnm), offsetof(struct headers, h_ctlcmd) };
  static const struct hdrdef exphdr = {
! 	expnm, STRLEN(expnm), offsetof(struct headers, h_expiry) };
  static const struct hdrdef distrhdr = {
  	distrnm, STRLEN(distrnm), offsetof(struct headers, h_distr) };
  static const struct hdrdef sendhdr = {

--- 59,65 -----
  static const struct hdrdef ctlhdr = {
  	ctlnm, STRLEN(ctlnm), 6 };
  static const struct hdrdef exphdr = {
! 	expnm, STRLEN(expnm), 14 };
  static const struct hdrdef distrhdr = {
  	distrnm, STRLEN(distrnm), 4 };
  static const struct hdrdef sendhdr = {
***************
*** 61,67
  static const struct hdrdef exphdr = {
  	expnm, STRLEN(expnm), offsetof(struct headers, h_expiry) };
  static const struct hdrdef distrhdr = {
! 	distrnm, STRLEN(distrnm), offsetof(struct headers, h_distr) };
  static const struct hdrdef sendhdr = {
  	sendnm, STRLEN(sendnm), offsetof(struct headers, h_sender) };
  const struct hdrdef xrefhdr = { xrefnm, STRLEN(xrefnm), -1 };

--- 61,67 -----
  static const struct hdrdef exphdr = {
  	expnm, STRLEN(expnm), 14 };
  static const struct hdrdef distrhdr = {
! 	distrnm, STRLEN(distrnm), 4 };
  static const struct hdrdef sendhdr = {
  	sendnm, STRLEN(sendnm), 18 };
  const struct hdrdef xrefhdr = { xrefnm, STRLEN(xrefnm), -1 };
***************
*** 63,69
  static const struct hdrdef distrhdr = {
  	distrnm, STRLEN(distrnm), offsetof(struct headers, h_distr) };
  static const struct hdrdef sendhdr = {
! 	sendnm, STRLEN(sendnm), offsetof(struct headers, h_sender) };
  const struct hdrdef xrefhdr = { xrefnm, STRLEN(xrefnm), -1 };
  
  static const struct hdrdef arthdr = {

--- 63,69 -----
  static const struct hdrdef distrhdr = {
  	distrnm, STRLEN(distrnm), 4 };
  static const struct hdrdef sendhdr = {
! 	sendnm, STRLEN(sendnm), 18 };
  const struct hdrdef xrefhdr = { xrefnm, STRLEN(xrefnm), -1 };
  
  static const struct hdrdef arthdr = {
***************
*** 67,73
  const struct hdrdef xrefhdr = { xrefnm, STRLEN(xrefnm), -1 };
  
  static const struct hdrdef arthdr = {
! 	artnm, STRLEN(artnm), offsetof(struct headers, h_artid) };
  
  static const struct hdrdef datrcvhdr = { datercvnm, STRLEN(datercvnm), -1 };
  static const struct hdrdef rcvhdr = { rcvnm, STRLEN(rcvnm), -1 };

--- 67,73 -----
  const struct hdrdef xrefhdr = { xrefnm, STRLEN(xrefnm), -1 };
  
  static const struct hdrdef arthdr = {
! 	artnm, STRLEN(artnm), 12 };
  
  static const struct hdrdef datrcvhdr = { datercvnm, STRLEN(datercvnm), -1 };
  static const struct hdrdef rcvhdr = { rcvnm, STRLEN(rcvnm), -1 };

henry@utzoo.uucp (Henry Spencer) (07/13/89)

In article <583@axis.fr> philip@axis.fr (Philip Peake) writes:
>...complaints from the compiler, about too complex expressions.
>The problem is the offset() macro, which calculates the offset of a structure
>member *at compile time*...

Alas, quite a few people have reported trouble with this one.  The offsetof()
macro really seems to strain compilers.  Those compilers will have to be
fixed eventually, since ANSI C requires said macro (that's where the idea
came from, in fact), but that's not much comfort now.  Unfortunately, Geoff
tells me that using that macro in that table made the code a whole lot
simpler...
-- 
$10 million equals 18 PM       |     Henry Spencer at U of Toronto Zoology
(Pentagon-Minutes). -Tom Neff  | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

rd@tarpit.uucp (Bob Thrush x210) (07/15/89)

In article <1989Jul13.154431.28974@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes:
>In article <583@axis.fr> philip@axis.fr (Philip Peake) writes:
>>...complaints from the compiler, about too complex expressions.
>>The problem is the offset() macro, which calculates the offset of a structure
>>member *at compile time*...
>Alas, quite a few people have reported trouble with this one.

  From earlier suggestions by Henry and Rick Richardson, the following
patch works around the offsetof macro problem.  (I have only tested this
with the large model.)

*** /tmp/hdrdefs.c	Sat Jul 15 10:55:17 1989
--- hdrdefs.c	Sun Jul  2 13:37:02 1989
***************
*** 17,28 ****
  #include "hdrint.h"		/* may define "const" */
  
  #ifndef offsetof
- #ifdef iAPX286
- #define offsetof(type, mem) ((int)&((type *)NULL)->mem)
- #else
  #define offsetof(type, mem) ((char *)&((type *)NULL)->mem - (char *)NULL)
! #endif  /* iAPX286 */
! #endif  /* offsetof */
  
  /* "mandatory" headers (also From:, Date:) */
  static const char msgnm[] =	"Message-ID:";	/* for rejection */
--- 17,24 ----
  #include "hdrint.h"		/* may define "const" */
  
  #ifndef offsetof
  #define offsetof(type, mem) ((char *)&((type *)NULL)->mem - (char *)NULL)
! #endif
  
  /* "mandatory" headers (also From:, Date:) */
  static const char msgnm[] =	"Message-ID:";	/* for rejection */
>-- 
>$10 million equals 18 PM       |     Henry Spencer at U of Toronto Zoology
>(Pentagon-Minutes). -Tom Neff  | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
-- 
Bob Thrush                 UUCP: {ucf-cs,rtmvax}!tarpit!rd
Automation Intelligence,   1200 W. Colonial Drive, Orlando, Florida 32804