Barry Schwarz <> writes:
> On Sat, 23 Jun 2007 19:54:37 -0700, Keith Thompson <kst->
> wrote:
>>Barry Schwarz <> writes:
>>> On Sun, 24 Jun 2007 00:10:45 -0000, SM Ryan
>>> <> wrote:
>>[...]
>>>>> struct bharath
>>>>> {
>>>>> int b;
>>>>> char c;
>>>>> float d;
>>>>> }
>>>>
>>>>A variable of type (struct bharath) will be allocated at
>>>>least sizeof(struct bharath) bytes. How a compiler allocates
>>>
>>> Would you care to give an example of when it will be allocated more
>>> than sizeof(srtuct bharath) bytes?
>>
>>malloc(sizeof(struct bharath)) can easily allocate more than
>>sizeof(struct bharath) bytes. Even for an object declaration, there
>>may be a gap between the object and the next object in memory.
>
> malloc does not allocate objects. It allocates the requested amount
> of space suitably aligned for any object.
That's arguable. An object is a "region of data storage in the
execution environment, the contents of which can represent values".
That's pretty much what malloc allocates.
> Why is everyone stripping out the next section of the original post
> where he made it clear he was talking about how the compiler allocates
> space for defined objects?
Um, what section was that? Here's the original post in its entirety:
| how much memory is allocated for following structure
| struct bharath
| {
| int b;
| char c;
| float d;
| }
|
| and how?
Just a type declaration.
Now I'm really just nitpicking here, not arguing any significant
point. It's true that anything that allocates an object of type
struct bharath, either an object declaration or a malloc call, can
easily allocate more that sizeof(struct bharath) bytes. It's also
true that the size of any struct bharath object is, by definition,
sizeof(struct bharath) bytes.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"