Questions tagged [packed]

78 questions
4
votes
2 answers

__attribute__((packed)) alternative

consider the following structure: typedef struct __attribute__((packed)) a{ int a1; int b2; char cArray[5]; int c3; } Mystruct; Now in my code, Im doing this: char source[50]; Mystruct mm; //... //initialization and other…
Dipto
  • 2,720
  • 2
  • 22
  • 42
3
votes
2 answers

Using attribute packed for classes in GCC

GCC doc says: You may only specify the packed attribute attribute on the definition of an enum, struct or union, not on a typedef that does not also define the enumerated type, structure or union. Does it mean that I cannot apply this attribute…
user1641854
3
votes
4 answers

Writing 'packed' structs to file using C

How can I "pack" and "write" a struct to a file using C so that: struct a { uint64_t a; char* b; uint16_t c; } a; a b; b.a = 3; b.b = "Hello"; b.c = 4; gets written to the file as 00 00 00 00 00 00 00 03 48 65 6c 6c 6f 00 00 04
Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
3
votes
2 answers

Packing bitfields even more tightly

I have a problem with bitfields in derived classes. With the g++ compiler, you can assign __attribute__((packed)) to a class and it will pack bitfields. So class A { public: int one:10; int two:10; int three:10; } __attribute__…
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
3
votes
2 answers

Sha 1 hashes and their length with the bit torrent protocol (magnets)?

I am scraping websites for information and it involves getting sha1 hashes of magnet links. I get all the magnet links with a simple preg_match_all but in my results I am getting weird results, I understand that a magnet hash in its hexadecimal form…
Griff
  • 1,647
  • 2
  • 17
  • 27
2
votes
1 answer

Weird result for packed number multiplication in an enhancement

I am missing a part to solve my problem. If I do this operation : TYPES: ty_p2 TYPE p DECIMALS 2. DATA: lv_test TYPE ty_p2. lv_test = '100.00' * '3.00'. I got this result in a program (specific program) on debugger view : this is the actual…
depth1
  • 135
  • 10
2
votes
2 answers

What does __attribute__((packed)) do to a union?

The spec (GCC type attributes amongst others) states that __attribute__((packed)) can be applied to a struct or a union. Since all union fields' storage overlap, what does the attribute actually do to a union? If you have various structures in the…
Willie Visagie
  • 171
  • 1
  • 14
2
votes
2 answers

How to properly access packed struct members

What is the correct way to access packed struct's members? struct __attribute__ ((packed)) MyData { char ch; int i; } void g(int *x); // do something with x void foo(MyData m) { g(&m.i); } void bar(MyData m) { int x = m.i; …
DDG
  • 147
  • 1
  • 6
2
votes
3 answers

ARM GCC Address of packed struct warning

In my code, I have something like this: #include typedef struct __attribute__((packed)) { uint8_t test1; uint16_t test2; } test_struct_t; test_struct_t test_struct; int main(void) { uint32_t *ptr = (uint32_t*) &test_struct; …
energetic
  • 897
  • 1
  • 5
  • 7
2
votes
1 answer

Creating new objects versus encoding data in primitives

Let's assume I want to store (integer) x/y-values, what is considered more efficient: Storing it in a primitive value like long (which fits perfect, due sizeof(long) = 2*sizeof(int)) using bit-operations like shift, or and a mask, or creating a…
NHSH
  • 69
  • 7
2
votes
2 answers

Sizeof of packed structure with bit fields

Consider this code: #include #include #ifdef __GNUC__ #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) #endif #ifdef _MSC_VER #define PACK( __Declaration__ ) __pragma(pack(push, 1)) __Declaration__…
pmor
  • 5,392
  • 4
  • 17
  • 36
2
votes
1 answer

How can I be sure that this C structure is packed both on 32 bit and 64 bit systems? Is "__attribute__((packed))" always necessary?

I'm trying to build a simple custom application layer protocol, essentially carrying a timestamp, plus some other useful information, in order to perform few network measurements between different Linux systems. The implementation, in my initial…
es483
  • 361
  • 2
  • 16
2
votes
2 answers

Fast list-product sign for PackedArray?

As a continuation of my previous question, Simon's method to find the list product of a PackedArray is fast, but it does not work with negative values. This can be "fixed" by Abs with minimal time penalty, but the sign is lost, so I will need to…
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
2
votes
0 answers

How to keep packed structs member sorted by declaration order in Doxygen

I use doxygen to document a C++ codebase which uses some packed structs to represent communication buffers. I usually like the alphabetical order of members doxygen uses because it makes it easier to find something in the documentation. However, I'd…
lgeorget
  • 400
  • 4
  • 13
2
votes
0 answers

Warning in assigning packed structure to global structure

I'm running on an (embedded) ARM architecture. I have a structure Brown: typedef struct { float A; float B; float C; }Brown; a packed structure Abo that contains Brown: #pragma pack(2) typedef struct { Brown Left; Brown…
Yuval
  • 21
  • 3