Hi,
>
I am beginner in C. Pls let me know what is packed array in C. Where
is it used?
Do you mean packed struct?
In this case, a idea of packed struct is provided as an extension by
some compilers. For example GCC provides a packed attribute:
packed
The packed attribute specifies that a variable or structure field
should have the smallest possible alignment—one byte for a variable, and
one bit for a field, unless you specify a larger value with the aligned
attribute.
I am beginner in C. Pls let me know what is packed array in C.
There is no such thing in ISO C. Any packed array extensions you may
encounter are compiler-specific, and not portable. If you want a
language where you can pack arrays portably, I believe Pascal lets you
do so.
I am beginner in C. Pls let me know what is packed array in C.
>
There is no such thing in ISO C. Any packed array extensions you may
encounter are compiler-specific, and not portable. If you want a
language where you can pack arrays portably, I believe Pascal lets you
do so.
>
Richard
Indeed it does, but it doesn't do what many people, apparently
including you, seem to think.
In the old, old days, implementations of many languages often wasted
memory by allocating a machine word to every element of an array, even
if a machine word was 32 or 36 or60 bits, and the elements of the
array were of a type that required far fewer bits. Hence the Pascal
"packed array" of characters.
That would be equivalent to a plain old ordinary array of
((un)signed)cha r in C.
I am beginner in C. Pls let me know what is packed array in C.
>>
>There is no such thing in ISO C. Any packed array extensions you may
>encounter are compiler-specific, and not portable. If you want a
>language where you can pack arrays portably, I believe Pascal lets you
>do so.
>
Indeed it does, but it doesn't do what many people, apparently
including you, seem to think.
>
In the old, old days, implementations of many languages often wasted
memory by allocating a machine word to every element of an array, even
if a machine word was 32 or 36 or60 bits, and the elements of the
array were of a type that required far fewer bits. Hence the Pascal
"packed array" of characters.
>
That would be equivalent to a plain old ordinary array of
((un)signed)cha r in C.
Not quite. Pascal (at least the version I used) allows packed arrays
of Boolean, where each element of the array occupies 1 bit. You could
also have packed arrays of, for example, a 2-bit type.
--
Keith Thompson (The_Other_Keit h) kst-u@mib.org <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"
On Tue, 25 Sep 2007 07:45:52 -0700, Sikandar wrote:
Hi,
>
I am beginner in C. Pls let me know what is packed array in C. Where
is it used?
There is no such thing as an unpacked array in C. Any array is
required to be contiguous in memory. For example,
(char *)&a[1] - (char *)&a[0] is *always* sizeof a[0], by
definition.
Types may have padding bits, but they are included also in single
objects of that type, so they are part of the type's size in all
aspects.
Did you mean something else, actually? If so, what?
--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.
In article <lnmyvazhk6.fsf @nuthaus.mib.or g>,
Keith Thompson <kst-u@mib.orgwrote:
>Not quite. Pascal (at least the version I used) allows packed arrays
>of Boolean, where each element of the array occupies 1 bit. You could
>also have packed arrays of, for example, a 2-bit type.
An analogy in C would be arrays of bitfields, but unfortunately C does
not provide these.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
In article <lnmyvazhk6.fsf @nuthaus.mib.or g>,
Keith Thompson <kst-u@mib.orgwrote:
>
>>Not quite. Pascal (at least the version I used) allows packed arrays
>>of Boolean, where each element of the array occupies 1 bit. You could
>>also have packed arrays of, for example, a 2-bit type.
>
An analogy in C would be arrays of bitfields, but unfortunately C does
not provide these.
They are pretty easy to fake, though.
--
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
Comment