c结构体按1字节对齐时, 结构体Fc_tgs_struct与Fc_tgs_struct_2的大小不一致,谁能解答一下

--------------------------------struct.h--------------------------------

#ifndef HEAD_STRUCT_C

#define HEAD_STRUCT_C

#include

#define BYTE_PACK_ON

#ifdef BYTE_PACK_ON

#pragma pack(1)

#endif

struct Fc_tgs_struct

{

char cFlag;

unsigned int uTime;

char sName[32];

char sPwd[64];

long long llVal;

};

struct Fc_tgs_struct_2

{

unsigned int uTime;

char sName[32];

char sPwd[64];

long long llVal;

char cFlag;

};

#ifdef BYTE_PACK_ON

#pragma pack()

#endif

#endif /// HEAD_STRUCT_C

--------------------------------cCallDemo.go--------------------------------

/**

* Created by huQg on 2018/5/31,031.

*/

package cCallDemo

/*

#include "struct.h"

*/

import "C"

import (

"fmt"

"unsafe"

)

func calccCallStruct() {

ctg := C.struct_Fc_tgs_struct{}

isz := unsafe.Sizeof(ctg)

fmt.Printf("struct Fc_tgs_struct's size = %d\n", isz)

ctg2 := C.struct_Fc_tgs_struct_2{}

isz = unsafe.Sizeof(ctg2)

fmt.Printf("struct Fc_tgs_struct_2's size = %d\n", isz)

}

--------------------------------cCallDemo_test.go--------------------------------

/*

* Created by huQg on 2018/5/31,031.

*/

package cCallDemo

import (

"testing"

)

func TestXYZ(t *testing.T) {

/// struct

calccCallStruct()

}

有疑问加站长微信联系(非本文作者)