public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: "Trenton D. Adams" <tadams@theone.dnsalias.com>
To: "'Jonathan Larmour'" <jlarmour@redhat.com>
Cc: "'Grant Edwards'" <grante@visi.com>,
	"'Andrew Lunn'" <andrew.lunn@ascom.ch>,
	"'eCos discussion'" <ecos-discuss@sources.redhat.com>
Subject: RE: [ECOS] Network programming for eCos under linux
Date: Wed, 08 Aug 2001 08:47:00 -0000	[thread overview]
Message-ID: <003101c12021$5ddfeb50$090110ac@TRENT> (raw)
In-Reply-To: <3B715735.608481A3@redhat.com>

Anyhow, thanks to ALL for the input!  I never knew that alignments would
matter.  I knew that on the x86, alignments don't matter and that it
just causes a performance hit if shorts, ints, etc are not accessed on
2, 4, or 8 byte boundaries.  But, since I've never worked on any other
platform other than a PC for programming purposes, I guess I wouldn't
know.  You learn something knew every day! :)

Anyhow, I'll keep that stuff in mind.

  > -----Original Message-----
  > From: ecos-discuss-owner@sources.redhat.com [ mailto:ecos-discuss-
  > owner@sources.redhat.com] On Behalf Of Jonathan Larmour
  > Sent: Wednesday, August 08, 2001 9:14 AM
  > To: Trenton D. Adams
  > Cc: 'Grant Edwards'; 'Andrew Lunn'; 'eCos discussion'
  > Subject: Re: [ECOS] Network programming for eCos under linux
  > 
  > "Trenton D. Adams" wrote:
  > >
  > >   > >
  > >   > > AFAICT, that should work on an ARM.  If it doesn't, it is a
  > >   > > compiler bug.
  > >   >
  > >   > Agreed. It would be different if you were accessing a more
  > strictly
  > >   > aligned
  > >   > type through a less strictly aligned type, e.g. casting a char
*
  > to
  > > a
  > >   > short
  > >   > * and dereferencing; as Grant says...
  > >   >
  > >
  > > So, you're not supposed to use a "char buffer[1024];" for a
generic
  > > buffer then?  If not, how should one create a generic buffer?
  > >
  > > So, the following gcc parameter would only warn when there is a
  > problem
  > > with that particular architecture that you're compiling for?
  > > -Wcast-align
  > 
  > Yes, but it would also warn even if you have taken care to ensure it
is
  > aligned.
  > 
  > > The one below would make it an error to cast from a char * to an
int
  > *?
  > > -mstrict-align
  > 
  > Yes.
  > 
  > > So, how would one go about making a buffer word aligned or DWORD
  > aligned
  > > just to be safe?
  > 
  > something along the lines of:
  > 
  > char buffer[1024];
  > #define ALIGNMENT 8
  > #define ALIGNUP(_x_) (((char *)(_x_) + ALIGN-1) & ~(ALIGN-1))
  > int *foo = ALIGNUP(buffer);
  > 
  > You could also use __alignof(int) to give the alignment but that's
  > obviously a GNU C-ism.
  > 
  > >   > > > Maybe i don't have the casts correct.
  > >   > >
  > >   > > There are other casts that are not going to work on ARM
  > >   > > architecture (accessing words on non-word boundaries, for
  > >   > > example).  That's not a compiler error, it's just another
way
  > >   > > to shoot yourself in the foot with C.
  > >   >
  > >   > Although it's worth mentioning that not all architectures
disallow
  > >   > unaligned accesses which is why people think they can get away
  > with
  > > it
  > >   > :).
  > >   >
  > >
  > > This goes back to the -Wcast-align.  If -Wall is on, that means
all
  > > warnings right?
  > 
  > Not all. Look at "info gcc" or "man gcc" to list the warnings that
are
  > and
  > aren't included e.g. -Wcast-align is not included. "man gcc" sez:
  > 
  >       The remaining `-W...' options are not implied by `-Wall'
because
  > they  warn  about
  >        constructions that we consider reasonable to use, on
occasion, in
  > clean programs.
  > 
  > Jifl
  > --
  > Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223)
  > 271062
  > Maybe this world is another planet's Hell -Aldous Huxley ||
  > Opinions==mine

  reply	other threads:[~2001-08-08  8:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-07 15:41 Trenton D. Adams
2001-08-08  0:35 ` Andrew Lunn
2001-08-08  6:27   ` Jonathan Larmour
2001-08-08  6:51     ` Andrew Lunn
2001-08-08  7:13       ` Grant Edwards
2001-08-08  7:52         ` Jonathan Larmour
2001-08-08  8:02           ` Andrew Lunn
2001-08-08  8:06           ` Trenton D. Adams
2001-08-08  8:14             ` Jonathan Larmour
2001-08-08  8:47               ` Trenton D. Adams [this message]
2001-08-08  8:58               ` Trenton D. Adams
2001-08-08  9:04                 ` Mark Salter
2001-08-08  9:06                 ` Jonathan Larmour
2001-08-08  9:19                   ` [ECOS] " Grant Edwards
2001-08-08  9:07                 ` Grant Edwards
2001-08-08  8:32             ` [ECOS] " Grant Edwards
2001-08-08  8:43               ` Trenton D. Adams
2001-08-08  8:57                 ` [ECOS] " Grant Edwards
2001-08-08  7:57   ` [ECOS] " Trenton D. Adams
2001-08-08  8:09     ` Grant Edwards
2001-08-08  8:14       ` Trenton D. Adams
2001-08-08  8:42         ` Grant Edwards
2001-08-08  8:21     ` Andrew Lunn
2001-08-08  8:27       ` Trenton D. Adams
2001-08-08  9:00       ` [ECOS] " Grant Edwards

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='003101c12021$5ddfeb50$090110ac@TRENT' \
    --to=tadams@theone.dnsalias.com \
    --cc=andrew.lunn@ascom.ch \
    --cc=ecos-discuss@sources.redhat.com \
    --cc=grante@visi.com \
    --cc=jlarmour@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).