Click here to Skip to main content
15,886,737 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionPragma pack, pointer, 32 vs 64 bits build Pin
Kochise17-Jul-09 0:55
Kochise17-Jul-09 0:55 
AnswerRe: Pragma pack, pointer, 32 vs 64 bits build [modified] Pin
Kochise17-Jul-09 1:17
Kochise17-Jul-09 1:17 
GeneralRe: Pragma pack, pointer, 32 vs 64 bits build Pin
Randor 17-Jul-09 1:54
professional Randor 17-Jul-09 1:54 
AnswerRe: Pragma pack, pointer, 32 vs 64 bits build Pin
Stuart Dootson17-Jul-09 1:50
professionalStuart Dootson17-Jul-09 1:50 
GeneralRe: Pragma pack, pointer, 32 vs 64 bits build [modified] Pin
Kochise17-Jul-09 5:44
Kochise17-Jul-09 5:44 
GeneralRe: Pragma pack, pointer, 32 vs 64 bits build Pin
Stuart Dootson17-Jul-09 13:05
professionalStuart Dootson17-Jul-09 13:05 
AnswerRe: Pragma pack, pointer, 32 vs 64 bits build Pin
cmk17-Jul-09 8:54
cmk17-Jul-09 8:54 
GeneralRe: Pragma pack, pointer, 32 vs 64 bits build Pin
Kochise17-Jul-09 10:32
Kochise17-Jul-09 10:32 
Yeah, I'm slownly working toward a solution to the problem, yet some stuff should still find an issue :

1- #pragma pack(8) align on a 8-byte boundary members of size >= 8, it doesn't add padding byte (what is in fact not a problem)
2- #pragma pack(1) align on a 1-byte boundary every members, nice for sending/receiving the struct as a frame. However that show the problem of software alignment fault on FPU members (float, double) and members whose size is greater than the current architechture word
3- #pragma pack(2) might lift up the problem upon most cases, but FPU members still get troubles
4- anonymous union is a nice stuff, yet I not always own the headers. Understand I work with compiled third party libraries and their header file. I work with struct coming out from these header files, and while I need the native format to deal with the library, I'd like to use the struct definition as a skeleton for my message's declaration as well. I 'just' need to enforce that the format of my message will be both 32 and 64 bit compatible (best is packing on 2 with 64 bits pointer).

#include <<foreign_lib.h>>

/* ======== foreign_lib.h ========
typedef struct foreign_struct
{ char  nMode;
  float fValue;
  int*  pArray;
};

foreign_struct* get_struct(void);
=== I HAVE NO CONTROL OVER THIS === */

// int send_frame(void* pBuffer, size_t nSize);

int test_struct(foreign_struct* frame)
{
#pragma pack(2)
  struct foreign_struct sFrame;
#pragma pack()

// foreign_struct : native struct format
// sFrame : my packed struct frame

  if(send_frame(frame, sizeof(foreign_struct))
  == send_frame(&sFrame, sizeof(sFrame)))
    return (int) TRUE;
  else
    return (int) FALSE;
}

int main(int argc, char *argv[])
{
  return test_struct(get_struct());
}


But thanks for you offer, good stuff to know !

Kochise

In Code we trust !

GeneralRe: Pragma pack, pointer, 32 vs 64 bits build Pin
cmk17-Jul-09 11:43
cmk17-Jul-09 11:43 
QuestionBHO IE7 problem when protected mode is ON? Pin
svt gdwl17-Jul-09 0:16
svt gdwl17-Jul-09 0:16 
AnswerRe: BHO IE7 problem when protected mode is ON? Pin
Michael Schubert17-Jul-09 0:51
Michael Schubert17-Jul-09 0:51 
GeneralRe: BHO IE7 problem when protected mode is ON? Pin
ThatsAlok18-Jul-09 7:45
ThatsAlok18-Jul-09 7:45 
QuestionSpecifying unicode strings Pin
Jon17-Jul-09 0:14
Jon17-Jul-09 0:14 
AnswerRe: Specifying unicode strings Pin
Randor 17-Jul-09 0:32
professional Randor 17-Jul-09 0:32 
GeneralRe: Specifying unicode strings Pin
Jon17-Jul-09 0:56
Jon17-Jul-09 0:56 
GeneralRe: Specifying unicode strings Pin
Michael Schubert17-Jul-09 1:10
Michael Schubert17-Jul-09 1:10 
GeneralRe: Specifying unicode strings Pin
Jon17-Jul-09 2:49
Jon17-Jul-09 2:49 
GeneralRe: Specifying unicode strings Pin
Michael Schubert17-Jul-09 3:12
Michael Schubert17-Jul-09 3:12 
GeneralRe: Specifying unicode strings Pin
Jon17-Jul-09 3:30
Jon17-Jul-09 3:30 
AnswerRe: Specifying unicode strings Pin
Michael Schubert17-Jul-09 0:41
Michael Schubert17-Jul-09 0:41 
GeneralRe: Specifying unicode strings Pin
Jon17-Jul-09 1:11
Jon17-Jul-09 1:11 
AnswerRe: Specifying unicode strings Pin
Adam Roderick J17-Jul-09 0:56
Adam Roderick J17-Jul-09 0:56 
GeneralRe: Specifying unicode strings Pin
Jon17-Jul-09 1:10
Jon17-Jul-09 1:10 
AnswerRe: Specifying unicode strings Pin
Nemanja Trifunovic17-Jul-09 3:46
Nemanja Trifunovic17-Jul-09 3:46 
QuestionIHTMLTxtRange::pasteHTML crash, any idea??? Pin
Ram-Murthi17-Jul-09 0:02
Ram-Murthi17-Jul-09 0:02 

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.