Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

I was asked a interview question for the below logic

I want a logic for reducing the size of structure using pragma and attributes in C for example

If i have structure

struct a
{
   int c;
   char b;
   char d;
};


The total size allocated to the above the structure was 8 bytes, But i want to reduce the above structure to 6 byte (i.e exact size) using the pragma and attributes logic can anyone explain this


Thanks
shan
Posted
Comments
Captain Price 10-Jan-14 11:04am    
2 bytes ? Who cares ? :D

Oh, the magic of Stack Overflow[^].
 
Share this answer
 
You are flagging C and linux. I don't know whether or not linux has a pack option, but in the windows world, you want to look at "#pragma pack". The MSDN info can be found here[^]...

For anything other than Windows, Google is your friend.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900