__align usage

This is a discussion on __align usage within the C Programming forums, part of the General Programming Boards category; I want to create a buffer variable that starts from an even address in memory. Does the __align achieve this? ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    14

    Question __align usage

    I want to create a buffer variable that starts from an even address in memory. Does the __align achieve this?

    What I found states that:-
    "Use the __align specifier to explicitly specify alignment and padding when declaring or defining data items."

    but it doesn't explicitly mention abt the starting address.
    So if I do something like this:-

    Code:
    __align(4) uint16 my_buffer[MAX_BUFFER_SIZE];
    Can I safely say that my_buffer starts from an even address and is aligned every word-size with 2-bytes padded?

    I'm new to this specifier so pardon any confusion I may cause in my description.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,654
    It might help if you said which compiler you are using.

    > I want to create a buffer variable that starts from an even address in memory. Does the __align achieve this?
    Given the type (which I guess is an unsigned short), the compiler probably aligns it to an even address anyway.
    The compiler will always align things to whatever most suits the data types you have.

    But your use of align seems consistent.

    > Can I safely say that my_buffer starts from an even address and is aligned every word-size with 2-bytes padded?
    For a simple array, there will be no internal padding.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2006
    Posts
    14
    Sorry for the late reply..been away from the boards.
    The compiler I'm using is ARM compiler.

    Is there a good site from whcih I can find out how the a compiler treat the __align command?
    I've did some intense searching but have yet to find any good sites.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,654
    First place to look is the manual.
    Then the website of the company that makes the compiler.
    Then the website of the company that makes the target board you're using containing the ARM processor.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    The pragma operator can be used to do the byte alignment.Check your compiler supports the pop and push arguments of pragma because these are not in ANSI standards.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  6. #6
    Registered User
    Join Date
    Jun 2006
    Posts
    14
    Alrite. Sounds like a good start. Thanks for the lead guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reduce CPU usage
    By patrick22 in forum Windows Programming
    Replies: 9
    Last Post: 07-10-2009, 02:13 PM
  2. Net cpu usage of pthreads?!
    By mynickmynick in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2008, 07:59 AM
  3. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  4. Calculating CPU Usage
    By vitaliy in forum Linux Programming
    Replies: 3
    Last Post: 08-21-2005, 09:38 AM
  5. Win2K Limiting CPU Usage?
    By drdroid in forum Tech Board
    Replies: 4
    Last Post: 03-31-2004, 01:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21