Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > More on alignment

Reply
Thread Tools

More on alignment

 
 
H.K. Kingston-Smith
Guest
Posts: n/a
 
      06-16-2008
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.

 
Reply With Quote
 
 
 
 
Kenny McCormack
Guest
Posts: n/a
 
      06-16-2008
In article <g367ts$7e9$(E-Mail Removed)>,
H.K. Kingston-Smith <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      06-16-2008
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.

 
Reply With Quote
 
rahul
Guest
Posts: n/a
 
      06-17-2008
On Jun 16, 10:29 pm, "H.K. Kingston-Smith" <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kamaelia 0.4.0 RELEASED - Faster! More Tools! More Examples! More Docs! ;-) Michael Python 4 06-26-2006 08:00 AM
With a Ruby Yell: more, more more! Robert Klemme Ruby 5 09-29-2005 06:37 AM
Regd---Justify option in Alignment. =?Utf-8?B?bWFudQ==?= ASP .Net 0 09-23-2005 07:35 AM
Vertical Alignment Gone Wrong, One More Time Arondelle HTML 12 07-18-2004 07:54 AM
Phase alignment ALuPin VHDL 0 05-17-2004 09:12 AM



Advertisments