Click here to Skip to main content
15,914,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with connecting to MySQL db from my own windows service application Pin
JudyL_MD28-Mar-07 2:14
JudyL_MD28-Mar-07 2:14 
GeneralRe: Problem with connecting to MySQL db from my own windows service application Pin
anumadhu28-Mar-07 21:06
anumadhu28-Mar-07 21:06 
QuestionRe: Problem with connecting to MySQL db from my own windows service application Pin
anumadhu28-Mar-07 23:18
anumadhu28-Mar-07 23:18 
AnswerRe: Problem with connecting to MySQL db from my own windows service application Pin
anumadhu30-Mar-07 2:12
anumadhu30-Mar-07 2:12 
Questionwhat is the role of #pragma pack(1) Pin
mo_nica88126-Mar-07 2:37
mo_nica88126-Mar-07 2:37 
AnswerRe: what is the role of #pragma pack(1) Pin
David Crow26-Mar-07 2:46
David Crow26-Mar-07 2:46 
AnswerRe: what is the role of #pragma pack(1) Pin
Cedric Moonen26-Mar-07 2:50
Cedric Moonen26-Mar-07 2:50 
AnswerRe: what is the role of #pragma pack(1) Pin
Nibu babu thomas26-Mar-07 3:16
Nibu babu thomas26-Mar-07 3:16 
mo_nica881 wrote:
in some program i always see "#pragma pack(1)" included in Header. what is the role of #pragma pack(1).


It's useful to disable structure member alignment. Value of 1 disables any alignment...

For eg:

struct aligntest
{
    char aChar;
    int nNum;
};


Normally sizeof( aligntest ) will return 8 but the actual size is 5. Extra 3 bytes is used for padding. This is done for efficiency sake.

This could be a problem if you are using functions like memcpy to copy native type values into structures for splitting them up and you want each part to be named...

For eg:
#pragma pack( push, 1 ) // Set alignment to 1
struct IntParts
{
   BYTE byPart1;
   BYTE byPart2;
   BYTE byPart3;
   BYTE byPart4;
};
#pragma pack( pop ) // Restore previous settings

int nSplit = 123213;
IntPart ip = { 0 };
memcpy( &ip, &nSplit, sizeof( ip ));


The above operation will be dangerous with padding since sizeof of int is 4 and the sizeof the structure should also be 4, hence you have to disable padding using #pragma pack( push, 1 ) and when you are done with the setting write another #pragma pack( pop ) which resets the setting.

You should not use 1 alignment always except for above reasons.


Nibu thomas
A Developer

Programming tips[^]  My site[^]

GeneralRe: what is the role of #pragma pack(1) Pin
Emil - Gabriel26-Mar-07 3:30
Emil - Gabriel26-Mar-07 3:30 
GeneralRe: what is the role of #pragma pack(1) Pin
Nibu babu thomas26-Mar-07 3:32
Nibu babu thomas26-Mar-07 3:32 
GeneralRe: what is the role of #pragma pack(1) Pin
David Crow26-Mar-07 3:59
David Crow26-Mar-07 3:59 
GeneralRe: what is the role of #pragma pack(1) Pin
Emil - Gabriel26-Mar-07 4:04
Emil - Gabriel26-Mar-07 4:04 
GeneralRe: what is the role of #pragma pack(1) Pin
David Crow26-Mar-07 4:17
David Crow26-Mar-07 4:17 
GeneralRe: what is the role of #pragma pack(1) Pin
Emil - Gabriel26-Mar-07 4:29
Emil - Gabriel26-Mar-07 4:29 
GeneralRe: what is the role of #pragma pack(1) Pin
David Crow26-Mar-07 4:39
David Crow26-Mar-07 4:39 
GeneralRe: what is the role of #pragma pack(1) Pin
Mark Salsbery26-Mar-07 9:53
Mark Salsbery26-Mar-07 9:53 
GeneralRe: what is the role of #pragma pack(1) Pin
Emil - Gabriel26-Mar-07 20:12
Emil - Gabriel26-Mar-07 20:12 
GeneralRe: what is the role of #pragma pack(1) Pin
Mark Salsbery27-Mar-07 6:25
Mark Salsbery27-Mar-07 6:25 
GeneralRe: what is the role of #pragma pack(1) Pin
Mark Salsbery27-Mar-07 6:42
Mark Salsbery27-Mar-07 6:42 
QuestionSetting minimum size for a CFrameWnd Pin
maxmaven26-Mar-07 2:15
maxmaven26-Mar-07 2:15 
AnswerRe: Setting minimum size for a CFrameWnd Pin
prasad_som26-Mar-07 2:29
prasad_som26-Mar-07 2:29 
GeneralRe: Setting minimum size for a CFrameWnd Pin
maxmaven26-Mar-07 3:03
maxmaven26-Mar-07 3:03 
QuestionRe: Setting minimum size for a CFrameWnd Pin
prasad_som26-Mar-07 3:07
prasad_som26-Mar-07 3:07 
AnswerRe: Setting minimum size for a CFrameWnd Pin
maxmaven26-Mar-07 4:54
maxmaven26-Mar-07 4:54 
GeneralRe: Setting minimum size for a CFrameWnd Pin
David Crow26-Mar-07 4:58
David Crow26-Mar-07 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.