JavaÓëCͨÐÅҪעÒâµÄ¼¸¸öÎÊÌâ
1.´óβ(big_endian)Сβ(little_endian)µÄÎÊÌâ
»ùÓÚWebµÄ²âÊÔÈí¼þÊÇÓÉC++Êý¾Ý²É¼¯·þÎñÆ÷³ÌÐòºÍ¿Í»§¶ËJavaÏÔʾ³ÌÐòÁ½²¿·Ö¹¹³É£¬Ç°ÕßÓÃC++£¬ºóÕßJavaÓïÑÔ£¬´æÔÚÊý¾ÝÒÆÖ²ÎÊÌâ¡£ÒòΪ
ÔÚ¼ÆËã»úϵͳÖУ¬µ±°üº¬Êý×ֵĶþ½øÖÆÎļþ´ÓÒ»¸ö½á¹¹ÒƵ½ÁíÒ»½á¹¹Ê±£¬¾Í³öÏÖ´óβСβÎÊÌâ¡£²»Í¬CPUÔÚ¶à×Ö½ÚÊý£¨ÈçËÄ×Ö½Úint£©´æ´¢Ê±ÓÐÁ½ÖÖ·½·¨£¬Ò»ÖÖ
·½·¨½ÐС⣨little_endian£©£¬Êý¾ÝµÄµÍ×Ö½Ú±»·ÅÖÃÔÚÁ¬Ðø´æ´¢ÇøµÄÊ×룬ÁíÒ»ÖÖ·½·¨½Ð´ó⣨big_endian£©£¬Êý¾ÝµÄ¸ß×Ö½Ú±»·ÅÖÃÔÚÁ¬
Ðø´æ´¢ÇøµÄÊ×λ¡£Intel 80×86¼Ò×å´¦ÀíÆ÷ÊÇ×îºóÒ»¸öÈÔÈ»¼á³ÖСβµÄÖ÷Òª½á¹¹¡£ËùÓÐÆäËûµÄCPU½á¹¹£¨Motorola
680×0ºÍËùÓÐRISCоƬ£©»òÕßÊÇ´¿´âµÄ´óβ»òÕßÊǼÈÊÊÓ¦´óβҲÊÊӦС⣬´óβ±»ÈÏΪÊǸü·ûºÏÂß¼µÄ·½·¨£©¡£µ±Êý×ÖÓÉСβ´¦ÀíÆ÷дÈëÎļþÈ»ºóÓÖÓÉ´óβ
´¦ÀíÆ÷¶ÁÈ¡£¨»òÕßµ¹¹ýÀ´£©Ê±£¬Êý×־ͻᱻ¸ãÂÒ£¨³ýÁË0ºÍ-1£©¡£
Ä¿Ç°ÔÚ±ÊÕß²ÎÓëµÄÏîÄ¿ÖÐƽ̨ÖÐÐĵÄGM
ServerÊÇCÓïÑÔʵÏÖµÄ,¶øÎÒÃÇÕâ±ßµÄGM
clientΪJavaʵÏֵģ¬×ÔÈ»ÐèÒª¿¼ÂÇÕâ¸öͨÐÅʱµÄ´óСβת»»£¬Ö÷ÒªÉæ¼°short,int,longÀàÐÍ£¬String,byteÀàÐͲ»ÐèҪת
»».
2.ÀàÐÍ×Ö½Ú´óСµÄÎÊÌâ
CÓïÑÔÖеĻù±¾ÀàÐÍÈçÏ£º
ÀàÐÍ
¶¨Òå
˵Ã÷
BYTE
typedef
unsigned char BYTE
µ¥×Ö½Ú
WORD
typedef
unsigned short WORD
Ë«×Ö½ÚÎÞ·ûºÅÕûÊý
SWORD
typedef
signed short SWORD
Ë«×Ö½Ú·ûºÅÕûÊý
DWORD
typedef
unsigned int DWORD
ËÄ×Ö½ÚÎÞ·ûºÅÕûÊý
SDWORD
typedef
signed int SDWORD
ËÄ×Ö½Ú·ûºÅÕûÊý
JavaµÄ°ËÖÖ»ù±¾Êý¾ÝÀàÐÍÈçÏ£º
byte 1×Ö½Ú
short
2×Ö½Ú
int 4×Ö½Ú
long
8×Ö½Ú £¨CÓïÑÔÖÐÊÇ4×Ö½Ú£©
char 2×Ö½Ú£¨CÓïÑÔÖÐÊÇ1×Ö½Ú£©
float
4×Ö½Ú
double 8
Ïà¹ØÎĵµ£º
ÎÒ¾õµÃ,ÔÚÊäÈëÊä³öº¯ÊýÖÐ,scanf()º¯Êý,Ó¦¸ÃÊÇ×îÂé·³µÄ,ÓÐʱËü¸øÎÒÃǵĽá¹ûºÜ¿ÉЦ,µ«ÊÇÒ»¶¨ÊÇÒ»ÔÒòµÄ....
Ê×ÏÈÉùÃ÷Ò»ÏÂ,ÕâƪÈÕÖ¾²»ÊǽéÉÜscanf()Öи÷ÖÖ¸ñʽ·ûÓ÷¨µÄÎÄÕÂ(ûÓÐÕâ¸ö±ØÒª,µ«ÊÇ´ó¼ÒÒ»¶¨Òª»áÓÃ).
ÎÒ³¢ÊÔÁ˺ܶàÖÖÊäÈë,°üÀ¨Ò»Ð©´íÎóµÄÁ·Ï°,Ôø¾¶Ôscanf()ÓÉÃÔãתÏòÇåÐÑ,ÓÖÓÉÇåÐÑÔÙ´ÎתÏòÃÔã......²»ÖªµÀºÎʱÊǸö ......
ÔÚcÖÐenumµÄʹÓúÍstructºÜÏñ
enum name{
a,b,c
};
struct name{
int a;
int b;
char c;
};
or
typedef struct{
int a;
int b;
char c;
}Name;
ʹÓõÄʱºò¶¼ÒªÏÈÉùÃ÷±äÁ¿
enum name n1,n2,n3;
n1=a;
n2=b;
n3=enum name(3-1);
struct name sn1,sn2;
s ......
gcc ÊÇcµÄ±àÒëÆ÷£¬g++ÊÇc++µÄ±àÒëÆ÷¡£ccÒ»°ãÊÇÒ»¸ö·ûºÅÁ¬½Ó£¬Ö¸Ïògcc¡£
CCÒ»°ãÊÇmakefileÀïÃæµÄÒ»¸öÃû×Ö£¬¾ßÌåÊÇʲô¸ù¾Ýʵ¼ÊÇé¿ö¾ö¶¨¡£
gccºÍg++¶¼ÊÇGNU(×éÖ¯)µÄÒ»¸ö±àÒëÆ÷¡£
ÎóÇøÒ»:gccÖ»ÄܱàÒëc´úÂë,g++Ö»ÄܱàÒëc++´úÂë
Á½Õ߶¼¿ÉÒÔ£¬µ«ÊÇÇë×¢Ò⣺
1,ºó׺Ϊ.cµÄ£¬gcc°ÑËüµ±×÷ÊÇC³ÌÐò£ ......
ÕâƪÈÕÖ¾»¹ÊÇÏÈ´ÓÒ»¸öÄܹ»ÔËÐÐÆðÀ´µÄÀý×Ó³ö·¢£¬Ò»µ©ÄÜ˳ÀûµÄ¿´µ½³ÌÐòµÄ³É¹¦ÔËÐУ¬ÄÇô½ÓÏÂÀ´µÄʼþÎÒÏëÓ¦¸ÃÊÇÎÊΪʲôÁË£¿ËƺõÕâÑù¸ü¼ÓÈÝÒ×Àí½âºÍÕÆÎÕ¡£
¶ÔÓÚsocket³ÌÐòµÄ¸ÅÄîÕâÀï¾Í²»¶àдÁË£¬µ«ÎÒÏàÐÅ£¬Èç¹ûÄÜ¿´ÍêÕâÕûƪÎÄÕ£¬ÎÒÏàÐŲ»»áÔÙÓÐÕâÑùµÄÒÉÎʵġ£
ÏÂÃ潫±àдһ¸öc/s½á¹¹µÄ³ÌÐò£¬Ö÷Òª¹¦ÄÜÊÇclient½«Ïòserver·¢Ë ......
¸ÅÊö¡¡¡¡
extern "C" °üº¬Ë«Öغ¬Ò壬´Ó×ÖÃæÉϼ´¿ÉµÃµ½£ºÊ×ÏÈ£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“extern”µÄ£»Æä´Î£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“C”µÄ¡£ÈÃÎÒÃÇÀ´Ïêϸ½â¶ÁÕâÁ½Öغ¬Òå¡£
¡¡¡¡£¨1£© ±»extern "C"ÏÞ¶¨µÄº¯Êý»ò±äÁ¿ÊÇexternÀàÐ͵Ä
¡¡¡¡externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©µÄ¹Ø¼ü×Ö£¬¸Ã¹Ø¼ü× ......