OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 8:40 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Packed Strcutures in GCC
PostPosted: Fri Oct 25, 2002 11:26 am 
Hi,

I need to know how I can create a packed structure in GCC, ie. it only has as many bytes as needed.

thanks.


Top
  
 
 Post subject: Re:Packed Strcutures in GCC
PostPosted: Fri Oct 25, 2002 2:04 pm 
typedef struct {
/* Code here */
} __attribute__((packed));


Top
  
 
 Post subject: Re:Packed Strcutures in GCC
PostPosted: Fri Oct 25, 2002 5:20 pm 
make sure you're not using this packed structure to read in data from a file.. cause it's very iffy. you're better off just reading in each byte to make sure you have the correct endian.

- Nick


Top
  
 
 Post subject: Re:Packed Strcutures in GCC
PostPosted: Fri Oct 25, 2002 8:45 pm 
With this would I put the name of the structure before __attribute__ ((packed)) like below?

typedef struct {
/* Code here */
} struct_name __attribute__((packed));

thanks.


Top
  
 
 Post subject: Re:Packed Strcutures in GCC
PostPosted: Sat Oct 26, 2002 11:20 am 
I dont think it really matters, i put my struct names after the __attribute__((packed))


Top
  
 
 Post subject: Re:Packed Strcutures in GCC
PostPosted: Wed Oct 30, 2002 7:54 am 
Also, this seems to work on both gcc and the Microsoft compiler:

Code:
#pragma pack(push, 1) /* use 1, 2, 4, etc. */
struct your_structure
{
};
#pragma pack(pop)


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 83 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group