public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Packed on a Arm Evaulation Board
@ 2000-06-20  7:27 jens.ohlund
  2000-06-20  7:36 ` Gary Thomas
  0 siblings, 1 reply; 6+ messages in thread
From: jens.ohlund @ 2000-06-20  7:27 UTC (permalink / raw)
  To: ecos-discuss

Hi!

I'm having a problem, I can't find out how to align data on even bytes.

That is, if I create a struct with 4 uint8 (unsigned char) I want the struct to be 8 bytes in size.

Why ? It's a requirment for a jvm I try to run. I've tried with __attribute__ ((packed)), which I thought worked when I tried to
make a struct with one byte, one short and one interger.
But I had lots of "funny" errors so I checked it up a bit more just to se that that 2 unsigned chars used only 16 bit together, not
16 bits EACH.

Anybody got any idea how I should do instead ?

yours
Jens Ohlund



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

* RE: [ECOS] Packed on a Arm Evaulation Board
  2000-06-20  7:27 [ECOS] Packed on a Arm Evaulation Board jens.ohlund
@ 2000-06-20  7:36 ` Gary Thomas
  2000-06-20  8:20   ` Jonathan Larmour
  0 siblings, 1 reply; 6+ messages in thread
From: Gary Thomas @ 2000-06-20  7:36 UTC (permalink / raw)
  To: jens.ohlund; +Cc: ecos-discuss

Try

  struct ABC { ...whatever... } __attribute__ ((aligned(1), packed));

On 20-Jun-00 jens.ohlund@secrc.abb.se wrote:
> Hi!
> 
> I'm having a problem, I can't find out how to align data on even bytes.
> 
> That is, if I create a struct with 4 uint8 (unsigned char) I want the struct to be 8 bytes in
> size.
> 
> Why ? It's a requirment for a jvm I try to run. I've tried with __attribute__ ((packed)), which I
> thought worked when I tried to
> make a struct with one byte, one short and one interger.
> But I had lots of "funny" errors so I checked it up a bit more just to se that that 2 unsigned
> chars used only 16 bit together, not
> 16 bits EACH.
> 
> Anybody got any idea how I should do instead ?
> 
> yours
> Jens Ohlund
> 
> 
> 

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

* Re: [ECOS] Packed on a Arm Evaulation Board
  2000-06-20  7:36 ` Gary Thomas
@ 2000-06-20  8:20   ` Jonathan Larmour
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Larmour @ 2000-06-20  8:20 UTC (permalink / raw)
  To: Gary Thomas; +Cc: jens.ohlund, ecos-discuss

Gary Thomas wrote:
> 
> Try
> 
>   struct ABC { ...whatever... } __attribute__ ((aligned(1), packed));

I've found from experience that you can't mix the aligned and packed
attributes. Also the aligned attribute only describes the alignment of the
structure, not of the fields inside it (For Gary's benefit, read the thread
subject "eCos 1.3.5 branch" around 4th/5th May from our internal lists).

Individual members of a struct can also
have __attribute__((packed)) on them, e.g. from gcc.info:

Here is a structure in which the field `x' is packed, so that it
immediately follows `a':  

  struct foo
  { 
    char a;
    int x[2] __attribute__ ((packed));
  };

Jifl
-- 
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS  Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow."  ||  These opinions are all my own fault

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

* Re: [ECOS] Packed on a Arm Evaulation Board
  2000-06-20  7:56 jens.ohlund
  2000-06-20  8:04 ` Sergei Organov
@ 2000-06-20  8:20 ` Jesper Skov
  1 sibling, 0 replies; 6+ messages in thread
From: Jesper Skov @ 2000-06-20  8:20 UTC (permalink / raw)
  To: jens.ohlund; +Cc: ecos-discuss

Try this:

  struct snejs
  {
    char bokstav1 __attribute__ ((aligned(2));
    char bokstav2 __attribute__ ((aligned(2));
    char bokstav3 __attribute__ ((aligned(2));
    char bokstav4 __attribute__ ((aligned(2));
    short siffra1 __attribute__ ((aligned(2));
    long siffra2;
  } mojs __attribute__ ((packed);


Jesper

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

* Re: [ECOS] Packed on a Arm Evaulation Board
  2000-06-20  7:56 jens.ohlund
@ 2000-06-20  8:04 ` Sergei Organov
  2000-06-20  8:20 ` Jesper Skov
  1 sibling, 0 replies; 6+ messages in thread
From: Sergei Organov @ 2000-06-20  8:04 UTC (permalink / raw)
  To: jens.ohlund; +Cc: ecos-discuss

Try this:

struct snejs
{
  char bokstav1 __attribute__((aligned(2));
  char bokstav2 __attribute__((aligned(2));
  char bokstav3 __attribute__((aligned(2));
  char bokstav4 __attribute__((aligned(2));
  short siffra1;
  long siffra2;
} mojs;

or even this:

struct snejs
{
  char bokstav1; char foo1;
  char bokstav2; char foo2;
  char bokstav3; char foo3;
  char bokstav4;
  short siffra1;
  long siffra2;
} mojs;


jens.ohlund@secrc.abb.se writes:
> Hi !
>
> Well, didn't work. The code looks like:
>   struct snejs
>   {
>     char bokstav1;
>     char bokstav2;
>     char bokstav3;
>     char bokstav4;
>     short siffra1;
>     long siffra2;
>   } mojs;
>
> And I tried to put the __attribute__ before snejs and after mojs, I tried to
> change the aligned(1) to aligned(2) as well.
>
> yours Jens
>
>
>
>
>
> ecos-discuss-owner@sourceware.cygnus.com 2000-06-20 16:36
>
>
> To: jens.ohlund@secrc.abb.se cc: ecos-discuss@sourceware.cygnus.com Subject:
> RE: [ECOS] Packed on a Arm Evaulation Board
>
> Security Level:?  Internal
>
>
> Try
>
>   struct ABC { ...whatever... } __attribute__ ((aligned(1), packed));
>
> On 20-Jun-00 jens.ohlund@secrc.abb.se wrote:
> > Hi!
> >
> > I'm having a problem, I can't find out how to align data on even bytes.
> >
> > That is, if I create a struct with 4 uint8 (unsigned char) I want the struct
> >to be 8 bytes in size.
> >
> > Why ? It's a requirment for a jvm I try to run. I've tried with
> >__attribute__ ((packed)), which I thought worked when I tried to make a
> >struct with one byte, one short and one interger.  But I had lots of "funny"
> >errors so I checked it up a bit more just to se that that 2 unsigned chars
> >used only 16 bit together, not 16 bits EACH.
> >
> > Anybody got any idea how I should do instead ?
> >
> > yours Jens Ohlund
> >
> >
> >

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

* RE: [ECOS] Packed on a Arm Evaulation Board
@ 2000-06-20  7:56 jens.ohlund
  2000-06-20  8:04 ` Sergei Organov
  2000-06-20  8:20 ` Jesper Skov
  0 siblings, 2 replies; 6+ messages in thread
From: jens.ohlund @ 2000-06-20  7:56 UTC (permalink / raw)
  To: ecos-discuss

Hi !

Well, didn't work. The code looks like:
  struct snejs
  {
    char bokstav1;
    char bokstav2;
    char bokstav3;
    char bokstav4;
    short siffra1;
    long siffra2;
  } mojs;

And I tried to put the __attribute__  before snejs and after mojs, I tried to change the aligned(1) to aligned(2) as well.

yours
Jens





ecos-discuss-owner@sourceware.cygnus.com
2000-06-20 16:36


To:   jens.ohlund@secrc.abb.se
cc:   ecos-discuss@sourceware.cygnus.com
Subject:  RE: [ECOS] Packed on a Arm Evaulation Board

Security Level:?         Internal


Try

  struct ABC { ...whatever... } __attribute__ ((aligned(1), packed));

On 20-Jun-00 jens.ohlund@secrc.abb.se wrote:
> Hi!
>
> I'm having a problem, I can't find out how to align data on even bytes.
>
> That is, if I create a struct with 4 uint8 (unsigned char) I want the struct to be 8 bytes in
> size.
>
> Why ? It's a requirment for a jvm I try to run. I've tried with __attribute__ ((packed)), which I
> thought worked when I tried to
> make a struct with one byte, one short and one interger.
> But I had lots of "funny" errors so I checked it up a bit more just to se that that 2 unsigned
> chars used only 16 bit together, not
> 16 bits EACH.
>
> Anybody got any idea how I should do instead ?
>
> yours
> Jens Ohlund
>
>
>





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

end of thread, other threads:[~2000-06-20  8:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-20  7:27 [ECOS] Packed on a Arm Evaulation Board jens.ohlund
2000-06-20  7:36 ` Gary Thomas
2000-06-20  8:20   ` Jonathan Larmour
2000-06-20  7:56 jens.ohlund
2000-06-20  8:04 ` Sergei Organov
2000-06-20  8:20 ` Jesper Skov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).