U0012@DGOGWDG5.BITNET ("GWDGV1::MOELLER") (05/11/88)
A question directed at VAX C gurus:
I would like to create a static table of address offsets in VAX C, like
static <type> base
extern <type> item1,item2,...
static readonly int tab[size] = {&item1 - &base,&item2 - &base, ...}
so I'd have POSITION-INDEPENDENT data only (for use in a shareable image)
Now simple adresses (+- offset) are legal initializers in C,
but not their difference, so the above program won't compile,
while
static readonly char *tab[size] = {&item1,&item2,...}
is o.k.
Do you know of a way to convince VAX C to do the desired
(compile-time) initialization?
Wolfgang J. Moeller, GWDG, D-3400 Goettingen, F.R.Germany | Disclaimer ...
Bitnet/Earn: U0012@DGOGWDG5 Phone: +49 551 201516 | No claim intendedLEICHTER@VENUS.YCC.YALE.EDU ("Jerry Leichter ", LEICHTER-JERRY@CS.YALE.EDU) (05/16/88)
[In VAX C,] I would like to create a static table of address offsets
in VAX C, like
static <type> base
extern <type> item1,item2,...
static readonly int tab[size] = {&item1 - &base,&item2 - &base, ...}
so I'd have POSITION-INDEPENDENT data only (for use in a shareable
image)
Now simple adresses (+- offset) are legal initializers in C, but not
their difference, so the above program won't compile, while
static readonly char *tab[size] = {&item1,&item2,...}
is o.k.
Do you know of a way to convince VAX C to do the desired
(compile-time) initialization?
Ah, but it ISN'T a compile-time initialization: The value of &item1-&base
isn't known to the compiler, nor can it be known until the program is linked.
This kind of initializer is certainly not allowable in standard C; many
linkers are unable to evaluate such expressions. On an architecture with a
segmented address space, the difference between two addresses may not even be
meaningful.
The VMS Linker could, in fact, evaluate such an expression if asked to, but
VAX C doesn't provide any mechanism for this.
You can build a table like tab[] in macro. I don't know Bliss well enough to
know if it can specify such a table; probably. I doubt any other VMS HLL will
let you do this.
The best I can suggest is that rather than using a whole bunch of separate
variables, you use one structure with a lot of fields, one per variable.
You then end up with a table of offsets to structure fields, which it IS
possible to compute at compile time; in fact, ANSI C even provides an offsetto
built-in macro to do this.
On the other hand, once you've put everything into one structure, you may find
that you really don't need the table anyway.
-- Jerrydhesi@bsu-cs.UUCP (Rahul Dhesi) (05/20/88)
In article <8805170934.AA05192@ucbvax.Berkeley.EDU> LEICHTER@VENUS.YCC.YALE.EDU ("Jerry Leichter ", LEICHTER-JERRY@CS.YALE.EDU) writes: > [In VAX C,] I would like to create a static table of address offsets > in VAX C, like It's better to say "VMS C" because it avoids mixing up hardware (VAX) with software (VMS). It also avoids the ambiguity of VMS versus UNIX or Ultrix etc. DEC document writers are quite confused about this issue, but we users and programmers should know better. -- Rahul Dhesi UUCP: <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi