forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

struct padding avoidance

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
jean



Joined: 05 Jan 2008
Posts: 489

PostPosted: Mon Jun 02, 2008 9:03 pm    Post subject: struct padding avoidance Reply with quote

I would like to set up a struct and avoid alignment in it. According to a website:
Quote:
Although the standard didn't provide any control in customizing the alignment and padding rules, many compilers provide this through non-standard extensions.


But in wikipedia i found:
Quote:
...some compilers use #pragma directives to specify packing inside source files...

Code:
#pragma pack(push)  /* push current alignment to stack */
#pragma pack(1)     /* set alignment to 1 byte boundary */
 
struct MyPackedData
{
    char Data1;
    long Data2;
    char Data3;
};
 
#pragma pack(pop)   /* restore original alignment from stack */

Quote:
The above directives are available in compilers from Microsoft, Borland, GNU and many others.


Just to stop those already writing "use search", this has nothing to do with __attribute__((aligned(16))) and i'm not experimenting directly the above code because my app has unexpected behaviours at the moment and i would not recognize the changes. If someone already had the same problem and wish to save me time writing some test code, then feel free to tell me if "#pragma pack(1) " works properly, or otherwise what's the pspsdk replacement if any. Thanks for your attention.
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Mon Jun 02, 2008 10:23 pm    Post subject: Reply with quote

Code:
typedef struct MyStruct
{
    ...
} __attribute__((packed)) MyStruct;


That's what gcc uses.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group