Questions tagged [packed]
78 questions
176
votes
3 answers
What is the meaning of "__attribute__((packed, aligned(4))) "
It is C language.It is written that:
typedef struct __attribute__((packed, aligned(4))) Ball {
float2 delta;
float2 position;
//float3 color;
float size;
//int arcID;
//float arcStr;
} Ball_t;
Ball_t *balls;
Please tell me…

Aaron Lee
- 2,060
- 2
- 15
- 20
48
votes
9 answers
Are packed structs portable?
I have some code on a Cortex-M4 microcontroller and'd like to communicate with a PC using a binary protocol. Currently, I'm using packed structs using the GCC-specific packed attribute.
Here is a rough outline:
struct Sensor1Telemetry {
int16_t…

Venemo
- 18,515
- 13
- 84
- 125
44
votes
6 answers
What is a "packed" structure in C?
I am going though some C code written for the Microchip C30 compiler and I often see structs defined as follows:
typedef struct __attribute__((__packed__))
{
IP_ADDR MyIPAddr; // IP address
IP_ADDR MyMask; …

PICyourBrain
- 9,976
- 26
- 91
- 136
26
votes
2 answers
Packed bit fields in c structures - GCC
I am working with structs in c on linux.
I started using bit fields and the "packed" attribute and I came across a wierd behavior:
struct __attribute__((packed)) {
int a:12;
int b:32;
int c:4;
} t1;
struct __attribute__((packed)) {
…

Danny Cohen
- 505
- 1
- 5
- 11
17
votes
1 answer
Why can't I return a reference to a packed field?
I use g++ to compile code with packed fields. However, I receive an error when trying to return a reference to a packed field.
Example:
struct __attribute__((packed)) Foo {
int* ptr;
uint16_t foo;
int*& getPtr(){
return ptr;
…

gexicide
- 38,535
- 21
- 92
- 152
16
votes
2 answers
Are there any difference between array and packed array in Delphi?
In C/C++ you always have
SizeOf(array[N] of T) = N * SizeOf(T);
In Pascal/Delphi you can use 'packed array' to be sure that the above assert is true, but does 'packed' specifier have any practical value for arrays in Delphi? I can't create an…

kludg
- 27,213
- 5
- 67
- 118
8
votes
3 answers
Is there a fast product operation for PackedArrays?
In Mathematica a vector (or rectangular array) containing all machine size integers or floats may be stored in a packed array. These objects take less memory, and some operations are much faster on them.
RandomReal produces a packed array when…

Mr.Wizard
- 24,179
- 5
- 44
- 125
7
votes
3 answers
Are unpacked struct in packed struct automatically packed?
Are unpacked struct in packed struct automatically packed by GCC?
In other words, do __packed__ attribute automatically propagates to nested structures?
That is to say:
struct unpackedStruct{
int16_t field1;
int32_t field2;
//…

quent
- 1,936
- 1
- 23
- 28
7
votes
2 answers
Printing packed structs in System Verilog
I have a packed struct defined as shown below
typedef struct packed {
logic bit1;
logic [7:0] byte1;
} MyPackedStruct;
MyPackedStruct myPackedStruct;
Is there any SV built in function that I could use to print the structures similar to…

Vissu
- 328
- 1
- 2
- 8
6
votes
4 answers
Nothing but "packed" records -- should I fix it?
While reviewing some code in our legacy Delphi 7 program, I noticed that everywhere there is a record it is marked with packed. This of course means that the record is stored byte-for-byte and not aligned to be faster for the CPU to access. The…

Earlz
- 62,085
- 98
- 303
- 499
6
votes
1 answer
Optimally packing a recursively templated struct without loss of alignment
I have a struct of 4 fields of types that come from template parameters:
template
struct __attribute__((aligned(8))) four_tuple {
typedef struct {
T1 t1;
T2 t2;
T3 t3;
T4 t4;
}…

dshin
- 2,354
- 19
- 29
6
votes
3 answers
min or gzip, which is better?
jquery-1.4.2.min.js is 71.8KB
Same file compressed through this tool, with gzip enabled, becomes 32.9 KB
Which is better? If latter, why doesn't jQuery provide a packed file too instead of just uncompressed and min versions?
My Question: One is…

eozzy
- 66,048
- 104
- 272
- 428
5
votes
1 answer
Packing a struct that contains a string
I just learned about padding, and I was trying to do some tests about it,
I tried to pack this struct :
struct B {
int a,b,c;
string s;
char x;
string t;
char y;
string u;
}__attribute__((packed))…

Othman Benchekroun
- 1,998
- 2
- 17
- 36
5
votes
1 answer
Size of packed struct with union of bit fields less than 8 bits in C
Is it possible in C to get the size of the following structure to be 2?
#include
struct union_struct {
char foo;
char bar : 2;
union {
char foobar1 : 6;
char foobar2 : 6;
};
};
int main(void)
{
…

croyd
- 1,075
- 1
- 11
- 15
4
votes
3 answers
How to get aligned array of packed structs in GCC C?
In GCC C, how can I get an array of packed structs, where each entry in the array is aligned?
(FWIW, this is on a PIC32, using the MIPS4000 architecture).
I have this (simplified):
typedef struct __attribute__((packed))
{
uint8_t …

nerdfever.com
- 1,652
- 1
- 20
- 41