* __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903]
@ 2004-08-04 15:43 Milind Changire
2004-08-04 15:58 ` Milind Changire
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Milind Changire @ 2004-08-04 15:43 UTC (permalink / raw)
To: gcc help
Following peice of code compiles under gcc and reports the size of
struct as 11, as expected. However g++ just does not like the code
and reports an error 'semicolon missing after enum declaration'
g++ 3.4.1 reports a 'warning: `packed' attribute ignored' and I get
the size of struct as 14.
I'd like to pack structures and cause enums to use mininum possible
space, mostly a single byte, under gcc 3.2.
Arch: i686
------
#include <stdio.h>
#pragma pack(1)
typedef enum {
Red,
Green,
Blue
} __attribute__((packed)) MYENUM;
struct pragma_struct_t {
char ch;
int val;
char ch2;
long len;
MYENUM color;
};
#pragma pack(0)
int main()
{
printf("sizeof(struct pragma_struct_t)= %d\n",
sizeof(struct pragma_struct_t));
return 0;
}
------
How do I get this to work under g++ 3.2?
Any patches or suggestions?
-Milind
^ permalink raw reply [flat|nested] 4+ messages in thread
* __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903]
2004-08-04 15:43 __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903] Milind Changire
@ 2004-08-04 15:58 ` Milind Changire
2004-08-04 16:52 ` Milind Changire
2004-08-04 18:52 ` Paweł Sikora
2 siblings, 0 replies; 4+ messages in thread
From: Milind Changire @ 2004-08-04 15:58 UTC (permalink / raw)
To: gcc help
Following peice of code compiles under gcc and reports the size of
struct as 11, as expected. However g++ just does not like the code
and reports an error 'semicolon missing after enum declaration'
g++ 3.4.1 reports a 'warning: `packed' attribute ignored' and I get
the size of struct as 14.
I'd like to pack structures and cause enums to use mininum possible
space, mostly a single byte, under gcc 3.2.
Arch: i686
------
#include <stdio.h>
#pragma pack(1)
typedef enum {
Red,
Green,
Blue
} __attribute__((packed)) MYENUM;
struct pragma_struct_t {
char ch;
int val;
char ch2;
long len;
MYENUM color;
};
#pragma pack(0)
int main()
{
printf("sizeof(struct pragma_struct_t)= %d\n",
sizeof(struct pragma_struct_t));
return 0;
}
------
How do I get this to work under g++ 3.2?
Any patches or suggestions?
-Milind
^ permalink raw reply [flat|nested] 4+ messages in thread
* __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903]
2004-08-04 15:43 __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903] Milind Changire
2004-08-04 15:58 ` Milind Changire
@ 2004-08-04 16:52 ` Milind Changire
2004-08-04 18:52 ` Paweł Sikora
2 siblings, 0 replies; 4+ messages in thread
From: Milind Changire @ 2004-08-04 16:52 UTC (permalink / raw)
To: gcc help
Following peice of code compiles under gcc and reports the size of
struct as 11, as expected. However g++ just does not like the code
and reports an error 'semicolon missing after enum declaration'
g++ 3.4.1 reports a 'warning: `packed' attribute ignored' and I get
the size of struct as 14.
I'd like to pack structures and cause enums to use mininum possible
space, mostly a single byte, under gcc 3.2.
Arch: i686
------
#include <stdio.h>
#pragma pack(1)
typedef enum {
Red,
Green,
Blue
} __attribute__((packed)) MYENUM;
struct pragma_struct_t {
char ch;
int val;
char ch2;
long len;
MYENUM color;
};
#pragma pack(0)
int main()
{
printf("sizeof(struct pragma_struct_t)= %d\n",
sizeof(struct pragma_struct_t));
return 0;
}
------
How do I get this to work under g++ 3.2?
Any patches or suggestions?
-Milind
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903]
2004-08-04 15:43 __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903] Milind Changire
2004-08-04 15:58 ` Milind Changire
2004-08-04 16:52 ` Milind Changire
@ 2004-08-04 18:52 ` Paweł Sikora
2 siblings, 0 replies; 4+ messages in thread
From: Paweł Sikora @ 2004-08-04 18:52 UTC (permalink / raw)
To: gcc-help
[-- Attachment #1: Type: text/plain, Size: 372 bytes --]
On Wednesday 04 of August 2004 17:48, Milind Changire wrote:
> Any patches or suggestions?
# g++ --version; g++ packed.cpp -o packed && ./packed
g++ (GCC) 3.4.2 20040730 (prerelease) (PLD Linux)
(...)
sizeof(...)= 14
arch == pentium3.
--
/* Copyright (C) 2003, SCO, Inc. This is valuable Intellectual Property. */
#define say(x) lie(x)
[-- Attachment #2: packed.cpp --]
[-- Type: text/x-c++src, Size: 466 bytes --]
#include <stdio.h>
typedef enum {
Red,
Green,
Blue
} MYENUM; // enum == int
struct pragma_struct_t {
char ch __attribute__((packed)); // 1 byte
int val __attribute__((packed)); // 4 bytes
char ch2 __attribute__((packed)); // 1 byte
long len __attribute__((packed)); // 4 bytes
MYENUM color __attribute__((packed)); // 4 bytes
// ========
// 14 bytes
};
int main()
{
printf("sizeof(...)= %d\n", sizeof(struct pragma_struct_t));
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-08-04 15:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-04 15:43 __attribute__((packed)) behavior with gcc and g++ [gcc version 3.2 20020903] Milind Changire
2004-08-04 15:58 ` Milind Changire
2004-08-04 16:52 ` Milind Changire
2004-08-04 18:52 ` Paweł Sikora
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).