4.2::SYSV compatability problem

Carl Resnikoff carl at rtech.ARPA
Thu Feb 7 02:57:45 AEST 1985


> 
> Apologies in advance if this has been resolved in the past or I am being
> dense (although that means several people here got denseness problems):
> 
> Under 4.2bsd if, say, you have a foo.h file with a line like:
> 
> 	int thing ;
> 
> and include it in a few .c files everything goes fine. In SYS5
> (we are running SYS5.2 on a 3B5) you get 'multiply defined' errors.
> Ok, not unexpected. I have in the past just changed such a file to
> something like:
> 
> #ifdef MAIN
> #define EXTERN
> #else
> #define EXTERN extern
> #endif
> 
> EXTERN int thing ;
> 
> And defined MAIN in only one place (like where main() occurs.)
> 
> Problem: Suppose now you are faced with a program with about 40 .h files
> and probably hundreds of such indiscretions. WORSE: many many typedefs
> making something like 'g/int /s//EXTERN int /' (if I may speak ed in
> mixed company) for each C type not enough.
> 
> What's a nurd to do? 'Fixing' SYS5 ld certainly comes to mind,
> (apparently berkeley already took this course once) any other
> suggestions welcome as it will be a few weeks before sources arrive and
> I got things to get on with....
> 
> Tx in advance.
> 
> 	-Barry Shein, Boston University


I have great sympathy for you, having once lived in a motel
room in Red Bank, New Jersey while fixing a very large (> 100,000
lines) C program written in BSD C so that SYS V C could load it.
However....

If you have any hope of porting your code to any other environments
(e. g. DEC C on VMS, Whitesmith C), fix your code and not SYS V ld.

DEC (VMS) C loader expects variables to be allocated with "globaldef"
and to be referenced with "globalref", while Whitesmith loader expects
all allocated variables to be initialized (or else no space is
allocated).  Besides, even on BSD, its nice to know where your
variables are really allocated, in case you ever want to tune your
programs to reduce paging, etc.

One way to handle these cases is  to have macros like

#define EXTERN extern /* or globalref or whatever */
#define GLOBAL globaldef /* or nothing */
#define FILL   ={0}     /* this works for structs, int's etc */
			/* you can also make it blank if non needed */

and you can say

int i FILL;
typedef struct {...} foo;
foo Foo1 FILL;
EXTERN int i;

Carl Resnikoff (ucbvax!mtxinu!rtech!carl)



More information about the Comp.unix.wizards mailing list