General
cancel
Showing results for 
Search instead for 
Did you mean: 

how can i use the #pragma pack() in following example

satish_16
Occasional Contributor

how can i use the #pragma pack() in following example

hi,
thanks for the information.
because of U i have got a new point.but till now also my problem was didn't solved.
i am using the #pragma pack()
in my example like following
#include
#pragma pack(push,<4>)
typedef struct messageheader
{
char x[2];
long logtime;
char alphachar[2];
short transactioncode;
short errorcode;
}msg;
#pragma pack(push)

#pragma pack(push,<4>)
typedef struct logonrequest
{
msg h;
short userid;
char pwd[8];
char newpwd[8];
char reserved[30];
}logon;
#pragma pack(push)


while running this program i am getting warnings like this:

malformed '#pragma pack(push[,id],)'
so,please make a solution for this and send it to me.
3 REPLIES
Michael Brailsford
Occasional Advisor

Re: how can i use the #pragma pack() in following example

Assuming that you are using gcc/g++ then you do it like this:

struct foo {
int bar;
int baz;
} __attributes__ (());

gcc does not recognize #pragma push and #pragma pop, those two pragmas are msvc++ #pragmas, if I am not mistaken.
Goran Koruga
Honored Contributor

Re: how can i use the #pragma pack() in following example

I mentioned this before here :

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xb230b941255cd71190080090279cd0f9,00.html

But they're obviously ignoring it.

G.
jonyav
Occasional Visitor

Re: how can i use the #pragma pack() in following example

Over 10 years later, I ran into the same problem and found this post, which was unhelpful. Later I found the problem myself, it consists of two parts:
1. gcc doesn't support #pragma pack up to version 2.96
2. gcc 2.96 and up supports #pragma pack, but at least the version I'm using (WindRiver's ccppc 2.96) supports it only if the line endings are Unix style (LF only).
Hope I'll be helpful for someone in the future.