易截截图软件、单文件、免安装、纯绿色、仅160KB

about pack and align for C/C++

http://msdn.microsoft.com/en-us/library/2e70t5y1(VS.80).aspx
#pragma
pack(  n  )
n : Valid values are 1, 2, 4, 8, and 16.the
alignment of a member will be on a boundary that is either a multiple of 
n
 or
a multiple of the size of the member
,
whichever is smaller.
The
default value for n
 is 8
成员变量对齐:选n
和该成员长度

最小值(的倍数)
结构ABCD中d的对齐方式,选n和sizeof(d)的最小值8,然后按8字节对齐!!!
sizeof大小:选n
和最大成
员长度
的最小值,对齐
例子:
#pragma
pack(8)
struct ABCD
{
bool
b;
short s;
double d;
};
int
main()
{
cout << offsetof(ABCD,
b) << endl;
cout << offsetof(ABCD,
s) << endl;
cout << offsetof(ABCD,
d) << endl;
cout << sizeof(ABCD) << endl;
}
output
is:

2
8
16
http://msdn.microsoft.com/en-us/library/83ythb65(VS.71).aspx
__declspec( align( n ) )
__declspec( align() ) 和 #pragma pack
是一对兄弟,前者规定了对齐的最小值,后者规定了对齐的最大值,两者同时出现时,前者拥有更高的优先级。 
例子:
#define
CACHE_ALIGN 64 
// Force each structure to be
in a different cache line. 
struct
__declspec(align(CACHE_ALIGN)) CUSTINFOAA { 
DWORD
   dwCustomerID;     // Mostly read-only 
wchar_t
 szName[100];      // Mostly read-only 
// Force the following members to be in a different cache line. 
__declspec(align(CACHE_ALIGN)) 
  int
nBalanceDue;           // Read-write 
FILETIME
ftLastOrderDate;  // Read-write 
}; 
int
main()
{
cout <<
offsetof(CUSTINFOAA, dwCustomerID) << endl;
cout
<< offsetof(CUSTINFOAA, szName) << endl;
cout
<< offsetof(CUSTINFOAA, nBalanceDue) << endl;
cout << offsetof(CUSTINFOAA, ftLastOrderDate) <<
endl;
cout << sizeof(CUSTIN


相关文档:

ubuntu下,C/C++通过JNI调用 JAVA类

之前写过一个实现了某种功能的java程序,但由于近日“工作”需要,又需要在c/c++中重新使用该功能。为了节省时间,我采取了在c/c++中调用java程序的方法,但之前没有接触过类似的东西,到网上一查,果然有类似的东西,心中暗喜ing...。查到的资料中有几个不错的网页:
      &nbs ......

entry point to c/c++ or Fortran MEX file

http://www.mathworks.com/access/helpdesk/help/techdoc/apiref/mexfunction.html
mexFunction (C and Fortran) -
Entry point to C/C++ or Fortran MEX-file
C Syntax
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[]);
Fortran
Syntax
subrouti ......

Java与C通信要注意的几个问题

1.大尾(big_endian)小尾(little_endian)的问题
基于Web的测试软件是由C++数据采集服务器程序和客户端Java显示程序两部分构成,前者用C++,后者Java语言,存在数据移植问题。因为
在计算机系统中,当包含数字的二进制文件从一个结构移到另一结构时,就出现大尾小尾问题。不同CPU在多字节数(如四字节int)存储时有两种方法 ......

C/C++文件操作[转载]

掌握文本文件读写的方法
了解二进制文件的读写方法
C++文件流:
fstream  // 文件流
ifstream  // 输入文件流
ofstream  // 输出文件流
//创建一个文本文件并写入信息
//同向屏幕上输出信息一样将信息输出至文件
#include<iomanip.h>
#include<fstream.h>
void main()
{
  ofstream f1("d:\\ ......

VC++与VB数据类型对应关系


 VC++
与VB
数据类型对应关系
  在做VC与vb程序间互相调用,需要注意两种语言不同编译器对数据类型的定义区别,此时两者数据类型的对应关系就显得十分的重要,对应关系以及声明方式如下所示。
VC++

VB

short
Integer
int
Long
long
Long
UNIT
Long
ULONG
Long
WORD
DWORDLon ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号