More on alignment

Discussion in 'C Programming' started by H.K. Kingston-Smith, Jun 16, 2008.

  1. Thanks to everybody who replied to my question on alignment on
    stack arrays. In a similar vein, what can one say about the alignment of
    p in

    char *p = alloca(N) ;

    where N can be any integer smaller than the stack space available? Is it
    going to follow similar alignment patterns as malloc(N) or as char p[N]?
    I am aware that using alloca() is not encouraged, but I have come across
    a few situations in which it would advantageous to do so.
     
    H.K. Kingston-Smith, Jun 16, 2008
    #1
    1. Advertising

  2. In article <g367ts$7e9$>,
    H.K. Kingston-Smith <> wrote:
    > Thanks to everybody who replied to my question on alignment on
    >st**k arrays. In a similar vein, what can one say about the alignment of
    >p in
    >
    > char *p = alloca(N) ;
    >
    >where N can be any integer smaller than the stack space available? Is it
    >going to follow similar alignment patterns as malloc(N) or as char p[N]?
    >I am aware that using alloca() is not encouraged, but I have come across
    >a few situations in which it would advantageous to do so.
    >


    You are now allowed to use that kind of language ("st**k" or "a((oca")
    in this newsgroup.

    Now, go wash your mouth out with soap.
     
    Kenny McCormack, Jun 16, 2008
    #2
    1. Advertising

  3. H.K. Kingston-Smith

    santosh Guest

    H.K. Kingston-Smith wrote:

    > Thanks to everybody who replied to my question on alignment on
    > stack arrays. In a similar vein, what can one say about the alignment
    > of p in
    >
    > char *p = alloca(N) ;
    >
    > where N can be any integer smaller than the stack space available? Is
    > it going to follow similar alignment patterns as malloc(N) or as char
    > p[N]? I am aware that using alloca() is not encouraged, but I have
    > come across a few situations in which it would advantageous to do so.


    Strictly speaking alloca is not defined by the C standard (or any other
    standard AFAIK) so it's behaviour cannot be accurately determined
    without examining your implementation of it. However all the
    implementations of alloca that I have seen have returned memory that is
    aligned for the strictest possible type in the system. Hence it can
    used to initialise any pointer type. In this way it's exactly like
    malloc, as far as I can see.
     
    santosh, Jun 16, 2008
    #3
  4. H.K. Kingston-Smith

    rahul Guest

    On Jun 16, 10:29 pm, "H.K. Kingston-Smith" <> wrote:
    > Thanks to everybody who replied to my question on alignment on
    > stack arrays. In a similar vein, what can one say about the alignment of
    > p in
    >
    > char *p = alloca(N) ;
    >
    > where N can be any integer smaller than the stack space available? Is it
    > going to follow similar alignment patterns as malloc(N) or as char p[N]?
    > I am aware that using alloca() is not encouraged, but I have come across
    > a few situations in which it would advantageous to do so.


    Quoting from the manual :

    The alloca() function is machine and compiler dependent. On many
    systems its implementation is
    buggy. Its use is discouraged.

    The more serious issue:
    On many systems alloca() cannot be used inside the list of arguments
    of a function call, because
    the stack space reserved by alloca() would appear on the stack in the
    middle of the space for the
    function arguments.
     
    rahul, Jun 17, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arondelle
    Replies:
    12
    Views:
    780
    Spartanicus
    Jul 18, 2004
  2. shess
    Replies:
    0
    Views:
    294
    shess
    Nov 24, 2003
  3. Michael
    Replies:
    4
    Views:
    437
    Matt Hammond
    Jun 26, 2006
  4. AW på ZRX

    Applet uses more and more CPU.

    AW på ZRX, Sep 11, 2006, in forum: Java
    Replies:
    3
    Views:
    376
    Tris Orendorff
    Sep 13, 2006
  5. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    223
    Jeff Wood
    Sep 29, 2005
Loading...

Share This Page