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

c/c++ ÄÚ´æ¶ÔÆë sizeof

   һƪ½²¶ÔÆë±È½ÏºÃµÄÎÄÕ£¬×ªÌùÈçÏÂ:
´óÖ±ê×¢Ò»¶þ:
1.ÄÚ´æ¶ÔÆë:¼ÆËã»úϵͳ¶Ô»ù±¾ÀàÐÍÊý¾ÝÔÚÄÚ´æÖдæ·ÅµÄλÖÃÓÐÏÞÖÆ£¬ËüÃÇ»áÒªÇóÕâЩÊý¾ÝµÄÊ×µØÖ·µÄÖµÊÇij¸öÊýk(ͨ³£ËüΪ4»ò8)µÄ±¶ÊýkÔò±»³ÆΪ¸ÃÊý¾ÝÀàÐ͵ĶÔÆëÄ£Êý(alignment modulus)
2.²»Í¬±àÒëÆ÷ĬÈϵÄ×î´ó¶ÔÆë×Ö½ÚÊýÊDz»Ò»ÑùµÄ,±ÈÈçvc==8,gcc==4,¿ÉÒÔͨ¹ý#progma pack (n)À´ÐÞ¸Ä,·ÖÎö³ÌÐòµÄʱºòҪעÒâ±àÒëÆ÷µÄÇø±ð
3.Ò»¸ö½á¹¹ÌåÀïÃæ,°´ÕÕalignment modulus×î´óµÄÊý¾Ý³ÉÔ±À´½øÐжÔÆë,³¬¹ý±àÒëÆ÷¹æ¶¨×î´óµÄ¶ÔÆë×Ö½Ú¸öÊý,°´±àÒëÆ÷×î´ó¶ÔÆë×Ö½Ú¸öÀ´
4.doubleÀàÐÍÔÚvcÀïÃæalignment modulus == 8,¶øÔÚgccÀïÃæÓÉÓÚĬÈÏ×î´ó¶ÔÆë¸öÊýÊÇ4,²»ÉèÖõĻ°,alignment modulus == 4
5.ÒòΪÊý×é¸÷ÔªËØÖ®¼ä²»ÄÜÓпÕ϶,ËùÒÔ{int a;char b;}
ÕâÖÖÇé¿ö,ĬÈÏÔÚVCÀïÃæÒ²ÐèÒªÕ¼8¸ö×Ö½Ú.
   ÕýÎÄÈçÏ£º
   µ±ÔÚCÖж¨ÒåÁËÒ»¸ö½á¹¹ÀàÐÍʱ£¬ËüµÄ´óСÊÇ·ñµÈÓÚ¸÷×Ö¶Î(field)´óС֮ºÍ£¿±àÒëÆ÷½«ÈçºÎÔÚÄÚ´æÖзÅÖÃÕâЩ×ֶΣ¿ANSI C¶Ô½á¹¹ÌåµÄÄÚ´æ²¼¾ÖÓÐʲôҪÇ󣿶øÎÒÃǵijÌÐòÓÖÄÜ·ñÒÀÀµÕâÖÖ²¼¾Ö£¿ÕâЩÎÊÌâ»òÐí¶Ô²»ÉÙÅóÓÑÀ´Ëµ»¹ÓеãÄ£ºý£¬ÄÇô±¾ÎľÍÊÔ×Å̽¾¿ËüÃDZ³ºóµÄÃØÃÜ¡£
    Ê×ÏÈ£¬ÖÁÉÙÓÐÒ»µã¿ÉÒԿ϶¨£¬ÄǾÍÊÇANSI C±£Ö¤½á¹¹ÌåÖи÷×Ö¶ÎÔÚÄÚ´æÖгöÏÖµÄλÖÃÊÇËæËüÃǵÄÉùÃ÷˳ÐòÒÀ´ÎµÝÔöµÄ£¬²¢ÇÒµÚÒ»¸ö×ֶεÄÊ×µØÖ·µÈÓÚÕû¸ö½á¹¹ÌåʵÀýµÄÊ×µØÖ·¡£±ÈÈçÓÐÕâÑùÒ»¸ö½á¹¹Ì壺
 
  struct vector{int x,y,z;} s;
  int *p,*q,*r;
  struct vector *ps;
 
  p = &s.x;
  q = &s.y;
  r = &s.z;
  ps = &s;
  assert(p < q);
  assert(p < r);
  assert(q < r);
  assert((int*)ps == p);
  // ÉÏÊö¶ÏÑÔÒ»¶¨²»»áʧ°Ü
    Õâʱ£¬ÓÐÅóÓÑ¿ÉÄÜ»áÎÊ:"±ê×¼ÊÇ·ñ¹æ¶¨ÏàÁÚ×Ö¶ÎÔÚÄÚ´æÖÐÒ²ÏàÁÚ?"¡£ ßí£¬¶Ô²»Æð£¬ANSI CûÓÐ×ö³ö±£Ö¤£¬ÄãµÄ³ÌÐòÔÚÈκÎʱºò¶¼²»Ó¦¸ÃÒÀÀµÕâ¸ö¼ÙÉè¡£ÄÇÕâÊÇ·ñÒâζ×ÅÎÒÃÇÓÀÔ¶ÎÞ·¨¹´ÀÕ³öÒ»·ù¸üÇåÎú¸ü¾«È·µÄ½á¹¹ÌåÄÚ´æ²¼¾Öͼ£¿Å¶£¬µ±È»²»ÊÇ¡£²»¹ýÏÈÈÃÎÒÃÇ´ÓÕâ¸öÎÊÌâÖÐÔÝʱ³éÉí£¬¹Ø×¢Ò»ÏÂÁíÒ»¸öÖØÒªÎÊÌâ————ÄÚ´æ¶ÔÆë¡£
    Ðí¶àʵ¼ÊµÄ¼ÆËã»úϵͳ¶Ô»ù±¾ÀàÐÍÊý¾ÝÔÚÄÚ´æÖдæ·ÅµÄλÖÃÓÐÏÞÖÆ£¬ËüÃÇ»áÒªÇóÕâЩÊý¾ÝµÄÊ×µØÖ·µÄÖµÊÇij¸öÊýk(ͨ³£ËüΪ4»ò8)µÄ±¶Êý£¬Õâ¾ÍÊÇËùνµÄÄÚ´æ¶ÔÆ룬¶øÕâ¸ökÔò±»³


Ïà¹ØÎĵµ£º

C/C++λ²Ù×÷

C/C++λ²Ù×÷
Ò»¡¢´«Í³µÄC·½Ê½Î»²Ù×÷£º
1.»ù±¾²Ù×÷£º
  ʹÓÃÒ»¸öunsigned int±äÁ¿À´×÷ΪλÈÝÆ÷¡£
2.²Ù×÷·û£º
|  °´Î»»ò²Ù×÷·û£ºresult=exp1|exp2;µ±exp1ºÍexp2ÖжÔӦλÖÐÖÁÉÙÓÐÒ»¸öΪ1ʱ£¬resultÖжÔӦλΪ1£¬·ñÔòΪ0¡£
&  °´Î»Óë²Ù×÷·û£º£ºresult=exp1&exp2;µ±exp1ºÍexp2ÖжÔӦλȫΪ1ʱ ......

C Traps and Pitfalls ¶ÁÊéÕª¼Ç

Óõ¥ÒýºÅÒýÆðµÄÒ»¸ö×Ö·ûʵ¼ÊÉÏ´ú±íÒ»¸öÕûÊý£¬ÕûÊýÖµ¶ÔÓ¦ÓÚ¸Ä×Ö·ûÔÚ±àÒëÆ÷²ÉÓõÄ×Ö·û¼¯ÖеÄÐòÁÐÖµ¡£
ÓÃË«ÒýºÅÒýÆðµÄ×Ö·û´®£¬´ú±íµÄÊÇÒ»¸öÖ¸ÏòÎÞÃûÊý×éÆðʼ×Ö·ûµÄÖ¸Õ룬¸ÃÊý×鱻˫ÒýºÅÖ®¼äµÄ×Ö·ûÒÔ¼°Ò»¸ö¶îÍâµÄ¶þ½øÖÆֵΪÁãµÄ×Ö·û'\0'³õʼ»¯¡£
printf("Hello world\n");
Óë
char hello[] = {'H', 'e', 'l', 'l', 'o', ' ' ......

PRO*C±à³ÌÖгöÏֵĴíÎó

°²×°ÍêOracleºó£¬Ê¹ÓÃPRO*C±àÒë.pcÎļþ£¬³öÏÖÒÔÏ´íÎó
proc: error while loading shared libraries: libclntsh.so.11.1:
cannot open shared object file: No such file or directory
½â¾ö·½·¨£º
ÔÚ/etc/profileÖÐÌí¼Ó
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib;
export LD_LIBRARY_PATH
È»ºó¿ÉÒÔ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ