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

¡¾×ª¡¿CµÄÁíÒ»ÖØÒªÊý¾Ý½á¹¹bit fields

½ñÌì¿´K&RµÄÊéµÄʱºò˳±ãÎÂÏ°ÁËCµÄÁíÒ»ÖØÒªÊý¾Ý½á¹¹bit-fields£¬ÎÒÏëbit-fieldsÔÚ±àдµ×²ãÇý¶¯
Çý¶¯³ÌÐòµÄʱºòÓ¦¸Ã±È½ÏºÃÓã¬Ëü¿ÉÒÔÈÆ¿ª"&"ºÍ"|"½øÐÐλ²Ù×÷£¬¶øÇÒ¸ü¼Ó½ÚÔ¼ÄÚ´æ¿Õ¼ä¡£·Ï»°²»¶à˵
ÁË£¬»¹ÊÇÏÈÀ´¿´¿´ËüµÄÕæÃæÄ¿°É£º
bit-fieldÀ´Ô´:
bit-fieldÊÇΪÁ˽ÚÔ¼´æ´¢¿Õ¼ä¶ø´´ÔìµÄÒ»ÖÖÊý¾Ý½á¹¹(to pack several objects into a single
machine word)
 
bit-fieldÓÃ;:
Externally-imposed data formats,such interfaces to hardware
devices,also often
require the ability to get a pieces of a word
 
¶¨Òå·½·¨:
struct (tag) {
bit-field list ~~~
} bit-field variable list;
 
Óɶ¨Òå·½·¨¿É¼û£¬bit-fieldÒ²ÊÇÒÔstructureµÄÐÎʽ×éÖ¯ÆðÀ´µÄÊý¾Ý½á¹¹£¬Ö»²»¹ýÊÇÒÔ¶þ½øÖƽøÐзַ¢
µÄ¶øÒÑ¡£ÆäÖÐbit-field list±íʾ·½·¨£º type fieldnamme:width;
width:fieldµÄ¿í¶È£¬ÒÔbit
±íʾ£¬»¹ÊǾٸöÀý×ÓÀ´¿´°É£º
 
struct bf{
unsigned int is_keyword:1;
unsigned int is_extern:1;
unsigned int is static:1;
}flags;
 
¶¨ÒåÁËÒ»¸öbit-field±äÁ¿flags£¬Ëü°üÀ¨3¸ö1-bitµÄfield£¬·ÃÎÊbit-fieldÆäʵºÍ·ÃÎÊÒ»°ãÊý¾Ý½á
¹¹µÄ³ÉÔ±Ò»Ñù£¬ÀýÈ磺
flags.is_static=0;
 
ÔÚ¶¨Òåbit-fieldµÄʱºò£¬ÓÐÒÔϼ¸µãҪעÒâ(K&R°æ±¾µÄ¹Ûµã)
1¡¢Almost everything about fields is implemention-dependent !
Whether a field may
   overlap a word boundary is implemention-defined.
2¡¢Fields can only be declared as intS,for protability,specify
signed or unsigned
   explicitly.
3¡¢unnamed field can be used for padding£¨Ã»ÓÐÃû×ÖµÄfield¿ÉÒÔÓÃÀ´×÷ΪÌî³ä»òÕßµ÷ÕûÓÃ)
   ÀýÈ磺
   struct bf{
   unsigned int a:2;
   unsigned int  :4; /*¸Ã4λ²»ÄÜÓÃ*/
   unsigned int b:2;
   };
 
 4¡¢Special width 0 may be used to force alignment at the next word
boundary.
   (Èç¹ûwidth=0µÄ»°£¬ÄÇôÏÂÒ»¸öfield¾Í±»Ç¿ÖÆ´æ·ÅÔÚÏÂÒ»¸öÄÚ´æµ¥ÔªÀïÃæÁË),ÀýÈç:
  
   struct bf{
   unsigned int a:2;
   unsigned int  :0; /*¿ÕµÄfield*/
   unsigned int b:2


Ïà¹ØÎĵµ£º

c/c++Ö§³Ö¿É±ä²ÎÊýµÄº¯Êý

c/c++Ö§³Ö¿É±ä²ÎÊýµÄº¯Êý£¬¼´º¯ÊýµÄ²ÎÊýÊDz»È·¶¨µÄ¡£
Ò»¡¢ÎªÊ²Ã´ÒªÊ¹Óÿɱä²ÎÊýµÄº¯Êý£¿
Ò»°ãÎÒÃDZà³ÌµÄʱºò£¬º¯ÊýÖÐÐÎʽ²ÎÊýµÄÊýĿͨ³£ÊÇÈ·¶¨µÄ£¬ÔÚµ÷ÓÃʱҪÒÀ´Î¸ø³öÓëÐÎʽ²ÎÊý¶ÔÓ¦µÄËùÓÐʵ¼Ê²ÎÊý¡£µ«ÔÚijЩÇé¿öÏÂÏ£Íûº¯ÊýµÄ²ÎÊý¸öÊý¿ÉÒÔ¸ù¾ÝÐèҪȷ¶¨£¬Òò´ËcÓïÑÔÒýÈë¿É±ä²ÎÊýº¯Êý¡£ÕâÒ²ÊÇc¹¦ÄÜÇ¿´óµÄÒ»¸ö·½Ã棬ÆäËüÄ³Ð©Ó ......

extern c ̸

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

[C´úÂë]ͨѶ¼

/*****************test.c****************/
#include <stdio.h>
#include <stdlib.h>
#include "addr.h"
int main()
{
 int flag=1;
 while(flag)
 {
  switch(choose_menu())
  {
  case 1:add_person();break;
  case 2:show_person_in ......

C/C++ Îļþ¶Áд²Ù×÷×ܽá

ÔÚ±à³ÌµÄ¹ý³ÌÖУ¬ÎļþµÄ²Ù×÷ÊÇÒ»¸ö¾­³£Óõ½µÄÎÊÌ⣬ÔÚC++BuilderÖУ¬¿ÉÒÔʹÓöàÖÖ·½·¨¶ÔÎļþ²Ù×÷£¬ÏÂÃæÎҾͰ´ÒÔϼ¸¸ö²¿·Ö¶Ô´Ë×÷Ïêϸ½éÉÜ£¬¾ÍÊÇ£º
1¡¢»ùÓÚCµÄÎļþ²Ù×÷£»
2¡¢»ùÓÚC++µÄÎļþ²Ù×÷£»
3¡¢»ùÓÚWINAPIµÄÎļþ²Ù×÷£»
4¡¢»ùÓÚBCB¿âµÄÎļþ²Ù×÷£»
5¡¢ÌØÊâÎļþµÄ²Ù×÷¡£
¡¡
Ò¼¡¢»ùÓÚCµÄÎļþ²Ù×÷
¡¡¡¡ÔÚANSI CÖУ¬ ......

C\C++ byte»òÕßcharÊý×éתintÖµ

¼ÙÉèÓÐchar a[2];
ÈçÒª°Ñaת»»ÎªintÖµ¡£Ó¦ÊÇÈçÏÂд·¨int b=*(int *)a;
¼´£¬ÏÈ°ÑÖ¸Õëa ת»»ÎªÒ»¸öintÖ¸Õ룬ȻºóÔÙ´Ë»ù´¡ÉÏÈ¡Öµ¡£
µ«ÊÇÁíÒ»ÖÖд·¨ int b=(int)(*a);ÊDz»¶ÔµÄ£¬*a È¡aµÄÄÚ´æµ¥ÔªÄÚÈÝ£¬ÒòΪÏÖÔÚaÊÇcharÖ¸Õ룬ËùÒÔÖ»»áÈ¡a[1]ÖÐÄÚÈÝ£¬×î´óΪ255. ÕâÀïҪ˵Ã÷µÄÊÇ£¬ÔÚ°Ñchar»òbyteÊý×éת»»ÎªÆäËûÀàÐ͵Äֵʱ£¬ÒªÏÈ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ