Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Packed array in C

Reply
Thread Tools

Packed array in C

 
 
Sikandar
Guest
Posts: n/a
 
      09-25-2007
Hi,

I am beginner in C. Pls let me know what is packed array in C. Where
is it used?

Thanks,
Sikandar

 
Reply With Quote
 
 
 
 
Pietro Cerutti
Guest
Posts: n/a
 
      09-25-2007
Sikandar wrote:
> 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.

source:
http://gcc.gnu.org/onlinedocs/gcc-4....ttributes.html


>
> Thanks,
> Sikandar
>



--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp
 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      09-25-2007
Sikandar <> wrote:

> 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
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      09-25-2007
On Tue, 25 Sep 2007 15:05:34 GMT, (Richard
Bos) wrote in comp.lang.c:

> Sikandar <> wrote:
>
> > 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)char in C.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-25-2007
Jack Klein <> writes:
> On Tue, 25 Sep 2007 15:05:34 GMT, (Richard
> Bos) wrote in comp.lang.c:
>> Sikandar <> wrote:
>> > 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)char 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_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"
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      09-25-2007
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.

 
Reply With Quote
 
karthikbalaguru
Guest
Posts: n/a
 
      09-26-2007
On Sep 25, 7:45 pm, Sikandar <sikandar...@gmail.com> wrote:
> Hi,
>
> I am beginner in C. Pls let me know what is packed array in C. Where
> is it used?
>
> Thanks,
> Sikandar


Coming across such a term in C for the first time

Did you call an array in your own words like that ?
Did you mean "what is an array in c ?"

Karthik Balaguru

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      09-26-2007
In article <>,
Keith Thompson <kst-> wrote:

>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

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      09-26-2007
Richard Tobin said:

> In article <>,
> Keith Thompson <kst-> wrote:
>
>>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
 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      09-26-2007
In article <>,
Richard Heathfield <> wrote:

>> An analogy in C would be arrays of bitfields, but unfortunately C does
>> not provide these.


>They are pretty easy to fake, though.


True, but so are for-loops.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
 
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
calling a function with parameters packed in array Sergey Emantayev Javascript 3 11-04-2008 02:51 PM
memset a member array of a packed structure parag.kanade@gmail.com C Programming 3 01-18-2006 11:01 PM
Problem with resources packed in a jar file Sameer Java 12 10-06-2005 06:53 PM
Implementing Legacy Byte Packed Message Interfaces Chris Java 6 11-07-2004 09:54 AM
How to decompress and display packed (zip) text file within ASP ? umberto ASP .Net 4 10-24-2003 08:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57