More on alignment

  • Thread starter H.K. Kingston-Smith
  • Start date
H

H.K. Kingston-Smith

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.
 
K

Kenny McCormack

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.
 
S

santosh

H.K. Kingston-Smith said:
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.
 
R

rahul

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top