473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

More on alignment

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.

Jun 27 '08 #1
4 2235
In article <g3**********@registered.motzarella.org>,
H.K. Kingston-Smith <HK***@yahoo.comwrote:
> 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.

Jun 27 '08 #2
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?
Nothing, really. Since alloca is not standardised, each implementation is free
to implement alloca in whatever way it likes with whatever semantics and
interface it likes, or indeed choose not to implement it at all.

This is one of those times when the only meaningful answer is to consult a
newsgroup that is dedicated to your particular implementation, and don't
assume that the answers you get apply to other implementations.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #3
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.

Jun 27 '08 #4
On Jun 16, 10:29 pm, "H.K. Kingston-Smith" <HK...@yahoo.comwrote:
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.
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Tina Li | last post by:
Hello, I've been struggling with a regular expression for parsing XML files, which keeps giving the run time error "maximum recursion limit exceeded". Here is the pattern string: ...
36
by: Bhalchandra Thatte | last post by:
I am allocating a block of memory using malloc. I want to use it to store a "header" structure followed by structs in my application. How to calculate the alignment without making any assumption...
10
by: j0mbolar | last post by:
for any pointer to T, does a pointer to T have different or can have different alignment requirement than a pointer to pointer to T? if so, where is the exact wording in the standard that would...
67
by: S.Tobias | last post by:
I would like to check if I understand the following excerpt correctly: 6.2.5#26 (Types): All pointers to structure types shall have the same representation and alignment requirements as each...
13
by: aegis | last post by:
The following was mentioned by Eric Sosman from http://groups.google.com/group/comp.lang.c/msg/b696b28f59b9dac4?dmode=source "The alignment requirement for any type T must be a divisor of...
10
by: haomiao | last post by:
I want to implement a common list that can cantain any type of data, so I declare the list as (briefly) --------------------------------------- struct list { int data_size; int node_num;...
55
by: fishpond | last post by:
How to declare a variable guaranteed to have the strictest possible alignment? -- The defense attorney was hammering away at the plaintiff: "You claim," he jeered, "that my client came at you...
2
by: somenath | last post by:
Hi All, I have one question regarding the alignment of pointer returned by malloc. In K&R2 page number 186 one union is used to enforce the alignment as mentioned bellow. typedef long...
2
by: uamusa | last post by:
I am Dynamically generating a proposal(report) in MS Word. By default the Paragraph Alignment is "Left". For the First 6 Paragraphs I set the Alignment to "Center", and then when attempting to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.