HP3000-L Archives

February 2001, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Reply To:
Date:
Tue, 13 Feb 2001 15:31:39 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (30 lines)
Ted Ashton <[log in to unmask]> wrote:
> I'm used to working with Pascal and being able to define variant records--
> 4 bytes which are either an integer or 2 shortints depending on how I need
> them.  Now I'm writing in C and I want to view the 14th and 15th elements of
> a short array as one int.  Obviously that is not aligned on a 4-byte boundary.
> On my linux box, I whipped out a quick program which used this construct:
>   *((int *)&short_array[13])
> and it worked nicely.

Apparently the C compiler on your linux box doesn't require an integer
to be aligned on a 32-bit boundary.  Or maybe short_array happened to
be aligned in such a way that the integer you wanted to extract actually
was aligned correctly.

> Fine, I try it on the 3000--Data memory protection trap.
> I'm using gcc.

In HP C/iX you could use the +u option.  Maybe gcc has something
equivalent.

> Is the answer that I need to quit doing that and go back to
> something along the lines of short_array[13]*65536+short_array[14]?

There are several ways to skin this cat, but if you want to use
this approach, you need to tweak your expression a little.  What you
have probably won't work as desired when the high-order bit of
short_array[14] is a 1.

Walter Murray

ATOM RSS1 RSS2