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

C struct ÖÐ×Ö½Ú¶ÔÆëÎÊÌâ

 VCÖÐÏÂÃ漸¸ö½á¹¹Ìå´óС·Ö±ðÊǶàÉÙÄØ
struct MyStruct
{
    double m4;
    char m1;
    int  m3£»
};
struct MyStruct {
    char m1;
    double m4;
    int m3;
};
#pragma pack(push)//±£´æ¶ÔÆë״̬
#pragma pack(16)  //ÉèÖÃΪ16×Ö½Ú¶ÔÆë
struct test
{
   char m1;
   int m3;  
   double m4;    
}; 
#pragma pack(pop)//»Ö¸´¶ÔÆë״̬
Èç¹ûÄãµÄ´ð°¸²»ÊÇ16£¬24ºÍ16£¬ÏàÐÅÏÂÃæµÄÄÚÈݶÔÄãºÜÓаïÖú¡£
1¡¢ sizeofÓ¦ÓÃÔڽṹÉϵÄÇé¿ö
Çë¿´ÏÂÃæµÄ½á¹¹£º
struct MyStruct
{
double dda1;
char dda;
int type
};
¶Ô½á¹¹MyStruct²ÉÓÃsizeof»á³öÏÖʲô½á¹ûÄØ£¿sizeof(MyStruct)Ϊ¶àÉÙÄØ£¿Ò²ÐíÄã
»áÕâÑùÇó£º
sizeof(MyStruct)=sizeof(double)+sizeof(char)+sizeof(int)=13
µ«Êǵ±ÔÚVCÖвâÊÔÉÏÃæ½á¹¹µÄ´óСʱ£¬Äã»á·¢ÏÖsizeof(MyStruct)Ϊ16¡£ÄãÖªµÀΪʲ
ôÔÚVCÖлáµÃ³öÕâÑùÒ»¸ö½á¹ûÂð£¿
Æäʵ£¬ÕâÊÇVC¶Ô±äÁ¿´æ´¢µÄÒ»¸öÌØÊâ´¦Àí¡£ÎªÁËÌá¸ßCPUµÄ´æ´¢Ëٶȣ¬VC¶ÔһЩ±äÁ¿µÄ
ÆðʼµØÖ·×öÁË“¶ÔÆë”´¦Àí¡£ÔÚĬÈÏÇé¿öÏ£¬VC¹æ¶¨¸÷³ÉÔ±±äÁ¿´æ·ÅµÄÆðʼµØÖ·Ïà¶ÔÓÚ½á
¹¹µÄÆðʼµØÖ·µÄÆ«ÒÆÁ¿±ØÐëΪ¸Ã±äÁ¿µÄÀàÐÍËùÕ¼ÓõÄ×Ö½ÚÊýµÄ±¶Êý¡£ÏÂÃæÁгö³£ÓÃÀàÐ͵Ä
¶ÔÆ뷽ʽ(vc6.0,32λϵͳ)¡£
ÀàÐÍ      ¶ÔÆ뷽ʽ£¨±äÁ¿´æ·ÅµÄÆðʼµØÖ·Ïà¶ÔÓڽṹµÄÆðʼµØÖ·µÄÆ«ÒÆÁ¿£©
Char      Æ«ÒÆÁ¿±ØÐëΪsizeof(char)¼


Ïà¹ØÎĵµ£º

C/C++Èí¼þ¹¤³Ìʦ±ÊÊÔÌâ

 
C/C++±ÊÊÔÌâϵÁÐ
Ô¤´¦ÀíÆ÷£¨Preprocessor£©
1. ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
1). #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
2). ¶®µÃÔ¤´¦ÀíÆ÷½«ÎªÄã¼ÆËã³ ......

[תÔØ]C/C++ÓïÑÔÎóÇøÒ» —— void main( )

 ÔÚÍøÉÏ¿´µ½ÁËÕâƪÎÄÕ£¬·Ç³£²»´í£¬»ñÒæ·Ëdz£¬ÓÚÊÇת¹ýÀ´£¬Ï£ÍûÄܶԴó¼ÒÓÐËùñÔÒæ¡£ÎÄÕÂÔ­×÷Õߣºantigloss http://free3.e-168.cn/antigloss/
     ºÜ¶àÈËÉõÖÁÊÐÃæÉϵÄһЩÊé¼®£¬¶¼Ê¹ÓÃÁËvoid main( ) £¬ÆäʵÕâÊÇ´íÎóµÄ¡£C/C++ ÖдÓÀ´Ã»Óж¨Òå¹ývoid main( ) ¡£C++ Ö®¸¸ Bjarne Stroustrup ÔÚËûµ ......

cÀïÃæµÄðºÅ——λÓò¶¨ÒåÆ÷

 typedef struct _RTP_header {
        /* byte 0 */
        #if (BYTE_ORDER == LITTLE_ENDIAN)
            unsigned char csrc_len:4;        /* expect 0 */
&nb ......

extern "C"Ïê½â

       C++ÓïÑԵĴ´½¨³õÖÔÊÇ“a better
C”£¬µ«ÊÇÕâ²¢²»Òâζ×ÅC++ÖÐÀàËÆCÓïÑÔµÄÈ«¾Ö±äÁ¿ºÍº¯ÊýËù²ÉÓõıàÒëºÍÁ¬½Ó·½Ê½ÓëCÓïÑÔÍêÈ«Ïàͬ¡£×÷ΪһÖÖÓûÓëC¼æÈݵÄÓïÑÔ£¬C++±£ÁôÁËÒ»²¿·Ö¹ý³Ì
ʽÓïÑÔµÄÌص㣨±»ÊÀÈ˳ÆΪ“²»³¹µ×µØÃæÏò¶ÔÏ󔣩£¬Òò¶øËü¿ÉÒÔ¶¨Òå²»ÊôÓÚÈκÎÀàµÄ ......

Hacks in C Programming Language

 ÏÂÃæÕâ¸ö³ÌÐòÊä³öʲô£¿
enum {false,true};
int main()
{
int i=1;
do
{
printf("%d\n",i);
i++;
if(i < 15)
continue;
}while(false);
return 0;
}

ÄãÏàÐÅô£¿Ï ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ