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:
0
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
Ïà¹ØÎĵµ£º
ÊÕ¼¯ÁË¿´Ò»ÏÂC/C++±ê×¼¿âʹÓõÄÏà¹ØÍøÕ¾£º
GNU¹ÙÍø£º
http://www.gnu.org/
¸ÃÍøÕ¾°üº¬C/C++±ê×¼¿âµÄʹÓ÷¶Àý£¬ÖµµÃ²Î¿¼£º
http://www.cplusplus.com/
ÔÚǶÈëʽµÚÈý·½Èí¼þÒÆֲʱ£¬»áʹÓÃSTLÄ£°å¿â×÷ÏàÓ¦ÒÆÖ²£¬ÈçAndroidƽ̨JNI·â×°¼°ÒÆÖ²µÈ¡£
¸ÃÍøÕ¾½éÉÜstlportµÄʹÓã¬stlportÒѿɳɹ¦ÒÆÖ²ÖÁAndroidµÈǶÈëʽƽ̨£¬²¢Ç ......
¸ÅÊö¡¡¡¡
extern "C" °üº¬Ë«Öغ¬Ò壬´Ó×ÖÃæÉϼ´¿ÉµÃµ½£ºÊ×ÏÈ£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“extern”µÄ£»Æä´Î£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“C”µÄ¡£ÈÃÎÒÃÇÀ´Ïêϸ½â¶ÁÕâÁ½Öغ¬Òå¡£
¡¡¡¡£¨1£© ±»extern "C"ÏÞ¶¨µÄº¯Êý»ò±äÁ¿ÊÇexternÀàÐ͵Ä
¡¡¡¡externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©µÄ¹Ø¼ü×Ö£¬¸Ã¹Ø¼ü× ......
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 ......
CÓïÑԵijõѧÕß³£·¸µÄÒ»¸öʧÎóÊǵ÷ÓÃϵͳ»òµÚÈý·½APIʱÍüÁËÔÚº¯ÊýÉùÃ÷Öбê×¢WINAPIµ÷Ó÷½Ê½£¬¶ø²ËÄñC++³ÌÐòԱҲÿÿÀ§»óΪʲô³ÉÔ±º¯Êý±ØÐëָʾΪCALLBACKÔÙÌí¼Óstatic¹Ø¼ü×Ö²ÅÄÜ×÷Ϊ»Øµ÷º¯Êý¡£ÔÚx86ϵͳÖУ¬´æÔÚ¶àÖÖº¯Êýµ÷ÓÃÔ¼¶¨¡£Èç¹ûµ÷ÓÃÕßÓë±»µ÷ÓÃÕß²ÉÓò»Í¬µÄµ÷ÓÃÔ¼¶¨£¬ºÜ¿ÉÄܵ¼Ö¶ÑÕ»ÆÆ»µ¡¢·Ç·¨·ÃÎʵÈÖÂÃü´íÎó¡£
ҲР......
ÕÆÎÕÎı¾Îļþ¶ÁдµÄ·½·¨
Á˽â¶þ½øÖÆÎļþµÄ¶Áд·½·¨
C++ÎļþÁ÷£º
fstream¡¡¡¡// ÎļþÁ÷
ifstream¡¡ // ÊäÈëÎļþÁ÷
ofstream¡¡ // Êä³öÎļþÁ÷
//´´½¨Ò»¸öÎı¾Îļþ²¢Ð´ÈëÐÅÏ¢
//ͬÏòÆÁÄ»ÉÏÊä³öÐÅÏ¢Ò»Ñù½«ÐÅÏ¢Êä³öÖÁÎļþ
#include<iomanip.h>
#include<fstream.h>
void main()
{
¡¡¡¡ofstream f1("d:\\ ......