Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C/C++ÖеĽṹÌå¶ÔÆëÎÊÌâ(ÄÚ´æ¶ÔÆë)

ÓÉÓÚ³ÌÐòÔËÐÐʱռÓõÄÄÚ´æ¹ý´ó£¬ËùÒÔÏë°ì·¨¸ø³ÌÐòÊÝÉí¡£
ÔÚµ÷ÊÔÖз¢ÏֽṹÌåÕ¼ÓõÄsize¾¹È»ºÍÔ¤ÏëµÄ²»Ò»Ñù£¬Ô­À´……
¿´¿´ÏÂÃæ½²µÄ°É£¬¿Ï¶¨»á²»Í÷´Ë¿´Å¶£¡
1,±ÈÈç:
struct{
    short a1;
    short a2;
    short a3;
}A;
struct{
    long a1;
    short a2;
}B;
sizeof(A)=6, sizeof(B)=8,Ϊʲô£¿
×¢£ºsizeof(short)=2,sizeof(long)=4
ÒòΪ:“³ÉÔ±¶ÔÆëÓÐÒ»¸öÖØÒªµÄÌõ¼þ,¼´Ã¿¸ö³ÉÔ±°´×Ô¼ºµÄ·½Ê½¶ÔÆë.Æä¶ÔÆëµÄ¹æÔòÊÇ,ÿ¸ö³ÉÔ±°´ÆäÀàÐ͵ĶÔÆë²ÎÊý(ͨ³£ÊÇÕâ¸öÀàÐ͵ĴóС)ºÍÖ¸¶¨¶ÔÆë²ÎÊý(ÕâÀïĬÈÏÊÇ8×Ö½Ú)ÖнÏСµÄÒ»¸ö¶ÔÆë.²¢ÇҽṹµÄ³¤¶È±ØÐëΪËùÓùýµÄËùÓжÔÆë²ÎÊýµÄÕûÊý±¶,²»¹»¾Í²¹¿Õ×Ö½Ú.”(ÒýÓÃ)
½á¹¹ÌåAÖÐÓÐ3¸öshortÀàÐͱäÁ¿£¬¸÷×ÔÒÔ2×Ö½Ú¶ÔÆ룬½á¹¹Ìå¶ÔÆë²ÎÊý°´Ä¬ÈϵÄ8×Ö½Ú¶ÔÆ룬Ôòa1,a2,a3¶¼È¡2×Ö½Ú¶ÔÆ룬Ôòsizeof(A)Ϊ6£¬ÆäÒ²ÊÇ2µÄÕûÊý±¶£»
BÖÐa1Ϊ4×Ö½Ú¶ÔÆ룬a2Ϊ2×Ö½Ú¶ÔÆ룬½á¹¹ÌåĬÈ϶ÔÆë²ÎÊýΪ8£¬Ôòa1È¡4×Ö½Ú¶ÔÆ룬a2È¡2×Ö½Ú¶ÔÆ룬½á¹¹Ìå´óС6×Ö½Ú£¬6²»Îª4µÄÕûÊý±¶£¬²¹¿Õ×Ö½Ú£¬Ôöµ½8ʱ£¬·ûºÏËùÓÐÌõ¼þ£¬Ôòsizeof(B)Ϊ8£»
¿ÉÒÔÉèÖóɶÔÆëµÄ
#pragma pack(1)
#pragma pack(push)
#pragma pack(1)
struct{
    short a1;
    short a2;
    short a3;
}A;
struct{
    long a1;
    short a2;
}B;
#pragma pack(pop)
½á¹ûΪsizeof( A)=6,sizeof( B)=6
************************
2,ÓÖÈç:
#pragma pack(8)
struct S1{
    char a;
    long b;
};
struct S2 {
    char c;
    struct S1 d;
    long long e;
};
#pragma pack()
sizeof(S2)½á¹ûΪ24.
³ÉÔ±¶ÔÆëÓÐÒ»¸öÖØÒªµÄÌõ¼þ,¼´Ã¿¸ö³ÉÔ±·Ö±ð¶ÔÆë.¼´Ã¿¸ö³ÉÔ±°´×Ô¼ºµÄ·½Ê½¶ÔÆë.
Ò²¾ÍÊÇ˵ÉÏÃæËäȻָ¶¨ÁË°´8×Ö½Ú¶ÔÆë,µ«²¢²»ÊÇËùÓеijÉÔ±¶¼ÊÇÒÔ8×Ö½Ú¶ÔÆë.Æä¶ÔÆëµÄ¹æÔòÊÇ,ÿ¸ö³ÉÔ±°´ÆäÀàÐ͵ĶÔÆë²ÎÊý(ͨ³£ÊÇÕâ¸öÀàÐ͵ĴóС)ºÍÖ¸¶¨¶ÔÆë²ÎÊý(ÕâÀïÊÇ8×Ö½Ú)ÖнÏСµÄÒ»¸ö¶ÔÆë.²¢ÇҽṹµÄ³¤¶È±ØÐëΪËùÓùýµÄËùÓжÔÆë²ÎÊýµÄÕûÊý±¶,²»¹»¾Í²¹¿Õ×Ö½Ú.
S1ÖÐ,³ÉÔ±aÊÇ1×Ö½ÚĬÈÏ°´1×Ö½Ú¶ÔÆë,Ö¸¶¨¶ÔÆë²ÎÊýΪ8,ÕâÁ½¸öÖµÖÐÈ¡1,a°´1×Ö½Ú¶ÔÆë;³ÉÔ±bÊÇ4¸ö×Ö½Ú,ĬÈÏÊÇ°´4×Ö½Ú¶ÔÆë,Õâʱ¾Í°´4×Ö½Ú¶ÔÆë,ËùÒÔ


Ïà¹ØÎĵµ£º

linux C ¶ÁȡĿ¼Îļþ²¢Í³¼ÆÎļþÊý

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
#define MAX 1024
int get_file_count(char *root)
{
 DIR *dir;
 struct dirent * ptr;
 int total = 0;
 char path[MAX];
 dir = opendir(root ......

unix C ¡¢delphiµÄ¶àÓïÑÔÎı¾×Ö·û»»ÐеÄÎÊÌâ

½ñÌìÏîÄ¿×é·¢ÉúÒ»¸öÊÂÇé¾ÍÊÇ£¬ºǫ́aixÉ϶ԶàÓïÑÔÎı¾£¨Ó¢Óï+ºº×Ö£©»»ÐÐÎÊÌâ¸ã²»Ì«Çå³þ¡£
×îÔçǰ̨µÄ¶à×Ö·ûµÄ´úÂëÎÒ¼ì²éÁËһϣ¨°´ÕÕ0-128ÒÔÍâËãÖÐÎĵĴúÂ룩·¢ÏÖ²»ÊÇ°²È«µÄ´úÂë¡£
(delphi 7.0)
delphi°²È«µÄ»ìºÏ×Ö·ûµÄ²Ù×÷·½·¨ÊÇ£º
ÔÚstrsUtilsµ¥ÔªÖÐ
leftstr
MidStr
Rightstr
aixÏÂÊÇ£º ......

C/C++ÓÚJavaÖ®¼äµÄ»¥Ïàµ÷ÓÃ

ÀûÓÃJNI¼¼Êõ£¬¿ÉÒÔ×öµ½C/C++ÓëJavaÖ®¼äµÄÏ໥µ÷Óá£
1¡¢Javaµ÷ÓÃC/C++½Ó¿Ú
Õâ¸öÊÇJNI×î»ù±¾µÄÓ¦Óã¬JNIÓкܶàÕâ·½ÃæµÄÀý×Ó´úÂë¡£Ò»°ã°ÑC/C++д³É¶¯Ì¬Á´½Ó¿â£»ÔÚJava³ÌÐòÔÚLoadLibrary£¬ÀûÓÃnative½Ó¿Ú£¬¼´¿ÉÍê³Éµ÷Óá£
2¡¢C/C++»Øµ÷Java½Ó¿Ú
ÕâÖÖÓ÷¨£¬JNIµÄÀý×ӱȽÏÉÙ¡£Æäʵ£¬Ò²±È½Ï¼òµ¥£¬JNIÒ²ÌṩÁËÕâÑùµÄ½Ó¿Ú¡ ......

C/C++Í·ÎļþÒ»ÀÀ


C¡¢´«Í³ C++

#include <assert.h>¡¡¡¡¡¡¡¡
//É趨²åÈëµã
#include <ctype.h>¡¡¡¡¡¡¡¡
//×Ö·û´¦Àí
#include <errno.h>¡¡¡¡¡¡¡¡
//¶¨Òå´íÎóÂë
#include <float.h>¡¡¡¡¡¡¡¡
//¸¡µãÊý´¦Àí
#include <fstream.h>¡¡¡¡¡¡
//ÎļþÊäÈ룯Êä³ö
#include <iomanip.h>¡¡ ......

C/C++³ÌÐòÔ±³£¼ûÃæÊÔÌâÉîÈëÆÊÎö


1.ÒýÑÔ   ±¾ÎĵÄд×÷Ä¿µÄ²¢²»ÔÚÓÚÌṩC/C++³ÌÐòÔ±ÇóÖ°ÃæÊÔÖ¸µ¼£¬¶øÖ¼ÔÚ´Ó¼¼ÊõÉÏ·ÖÎöÃæÊÔÌâµÄÄÚº­¡£ÎÄÖеĴó¶àÊýÃæÊÔÌâÀ´×Ô¸÷´óÂÛ̳£¬²¿·ÖÊÔÌâ½â´ðÒ²²Î¿¼ÁËÍøÓѵÄÒâ¼û-¡£
 Ðí¶àÃæÊÔÌâ¿´ËƼòµ¥£¬È´ÐèÒªÉîºñµÄ»ù±¾¹¦²ÅÄܸø³öÍêÃÀµÄ½â´ð¡£ÆóÒµÒªÇóÃæÊÔÕßдһ¸ö×î¼òµ¥µÄstrcpyº¯Êý¶¼¿É¿´³öÃæÊÔÕßÔÚ¼¼ÊõÉϾ¿¾¹´ïµ½Á ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ