# C程序设计语言--第六章:结构 原

fzyz_sb

6.2 结构与函数

``````struct point{
int x;
int y;
};

struct rect{
struct point pt1;
struct point pt2;
};``````

``````struct point makepoint( int x, int y )
{
struct point temp;
temp.x = x;
temp.y = y;

return temp;
}``````

``````struct rect screen;
struct point middle;
screen.pt1 = makepoint( 0, 0 );
screen.pt2 = makepoint( XMAX, YMAX );
middle = makepoint( ( screen.pt1.x + screen.pt2.x ) / 2, ( screen.pt1.y + screen.pt2.y ) / 2 );``````

``````struct point addpoint( struct point p1, struct point p2 )
{
p1.x += p2.x;
p1.y += p2.y;

return p1;
}``````

``struct point *pp;``

6.3 结构数组

``````#include <stdio.h>
#include <ctype.h>
#include <string.h>

struct key{
char *word;
int count;
} keytab[] = {
"auto", 0,
"break", 0,
"case", 0,
"char", 0,
"const", 0,
"continue", 0,
"default", 0,
"unsigned", 0,
"void", 0,
"volatile", 0,
"while", 0
};

#define NKEYS ( sizeof( keytab ) / sizeof( keytab[ 0 ] ) )

#define MAXWORD 100

int getword( char *, int );
int binsearch( char *, struct key *, int );

int main(void)
{
int n;
char word[ MAXWORD ];

while ( getword( word, MAXWORD ) != EOF ){
if ( isalpha( word[ 0 ] ) ){
if ( ( n = binsearch( word, keytab, NKEYS ) ) >= 0 ){
keytab[ n ].count++;
}
}
}

for ( n = 0; n < NKEYS; n++ ){
if ( keytab[ n ].count > 0 ){
printf("%4d %s\n", keytab[ n ].count, keytab[ n ].word );
}
}

return 0;
}

int binsearch( char *word, struct key *tab, int n )
{
int cond;
int low, high, mid;

low = 0;
high = n - 1;
while ( low <= high ){
mid = ( low + high ) / 2;
if ( ( cond = strcmp( word, tab[ mid ].word ) ) < 0 ){
high = mid - 1;
}
else if ( cond > 0 ){
low = mid + 1;
}
else{
return mid;
}
}

return -1;
}

int getword( char *word, int lim )
{
int ch;
int isBreak = 0;
int isDoubleNote = 0;

while ( --lim && ( ch = getchar() ) != EOF ){
if ( '/' == ch ){
if ( '*' == ( ch = getchar() ) ){
isBreak = 1;
continue;
}
else if ( '/' == ( ch = getchar() ) ){
isDoubleNote = 1;
continue;
}
else{
*word++ = '/';
continue;
}
}
else if ( ( '*' == ch ) && isBreak ){
if ( '/' == ( ch = getchar() ) ){
isBreak = 0;
continue;
}
}
else if ( '\n' == ch && isDoubleNote ){
isDoubleNote = 0;
continue;
}
else if ( ( isalnum( ch ) || '_' == ch ) && ( 1 != isBreak ) && ( 1 != isDoubleNote ) ){
*word++ = ch;
}
else{
break;
}
}
*word = '\0';

return ch;
}``````

``````int getword( char *word, int lim )
{
int c, d, comment( void ), getch( void );
void ungetch( int );
char *w = word;

while ( isspace( c = getch() ) ){
;
}
if ( c != EOF ){
*w++ = c;
}

if ( isalpha( c ) || c == '_' || c == '#' ){
for ( ; --lim > 0; w++ ){
if ( !isalnum( *w = getch() ) && *w != '_' ){
ungetch( *w );
break;
}
}
}
else if ( c == '\'' || c == '"'){
for ( ; --lim > 0; w++ ){
if ( ( *w = getch() ) == '\\' ){	//转义字符
*++w = getch();
}
else if ( *w == c ){
w++;
break;
}
else if ( *w == EOF ){
break;
}
}
}
else if ( c == '/' ){
if ( ( d = getch() ) == '*' ){
c = comment();
}
else{
ungetch( d );
}
}

*w = '\0';

return c;
}

int comment( void )
{
int c;
while ( ( c = getch() ) != EOF ){
if ( c == '*' ){
if ( ( c = getch() ) == '/' ){
break;
}
else{
ungetch( c );
}
}
}

return c;
}``````
6.4 指向结构的指针

main和binsearch函数必须修改:

``````#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAXWORD 100

int getword( char *, int );
struct key *binsearch( char *, struct key *, int );

int main(void)
{
char word[ MAXWORD ];
struct key *p;

while ( getword( word, MAXWORD ) != EOF ){
if ( isalpha( word[ 0 ] ) ){
if ( ( p = binsearch( word, keytab, NKEYS ) ) != NULL ){
p->count++;
}
}
}
for ( p = keytab; p < keytab + NKEYS; p++ ){
if ( p->count > 0 ){
printf("%4d %s\n", p->count, p->word );
}
}

return 0;
}

struct key *binsearch( char *word, struct key *tab, int n )
{
int cond;
struct key *low = &tab[ 0 ];
struct key *high = &tab[ n ];
struct key *mid;

while ( low < high ){
mid = low + ( high - low ) / 2;
if ( ( cond = strcmp( word, mid->word ) ) < 0 ){
high = mid;
}
else if ( cond > 0 ){
low = mid + 1;
}
else{
return mid;
}
}

return NULL;
}``````

6.5 自引用结构

``````#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define MAXWORD 100
struct tnode{
char *word;
int count;
struct tnode *left;
struct tnode *right;
};
struct tnode *addtree( struct tnode *, char * );
void treeprint( struct tnode * );
int getword( char *, int );

int main( void )
{
struct tnode *root;
char word[ MAXWORD ];

root = NULL;
while ( getword( word, MAXWORD ) != EOF ){
if ( isalpha( word[ 0 ] ) ){
root = addtree( root, word );
}
}
treeprint( root );

return 0;
}

struct tnode *talloc( void );
char *strdup( char * );

struct tnode *addtree( struct tnode *p, char *w )
{
int cond;

if ( NULL == p ){
p = talloc();
p->word = strdup( w );
p->count = 1;
p->left = p->right = NULL;
}
else if ( ( cond = strcmp( w, p->word ) ) == 0 ){
p->count++;
}
else if ( cond < 0 ){
p->left = addtree( p->left, w );
}
else{
p->right = addtree( p->right, w );
}

return p;
}

void treeprint( struct tnode *p )
{
if ( NULL != p ){
treeprint( p->left );
printf("%4d %s\n", p->count, p->word );
treeprint( p->right );
}
}

struct tnode *talloc( void )
{
return ( struct tnode * )malloc( sizeof( struct tnode ) );
}

char *strdup( char *s )
{
char *p;

p = ( char * )malloc( strlen( s ) + 1 );
if ( NULL != p ){
strcpy( p, s );
}

return p;
}``````

``````#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAXLINE 128

typedef struct TREENODE{
char	*data;			//出现的单词
int		count;			//该单词出现的次数
struct	TREENODE *left;
struct	TREENODE *right;
} tNode;

typedef struct SLIST{
char		*tag;			//标签--前n个字母是相同的
tNode		*data;			//前n个相同字母所保存的树
struct		SLIST *left;
struct		SLIST *right;
} sList;

sList *addList( sList *treeList, char *line );	//将一行的单词增加到列表中
void printNode( tNode *treeNode );
void printList( sList *treeList );				//打印列表
char *getword( char *line, char *word );					//从一行中逐个获取单词
sList *insertList( sList *treeList, char *tag, char *word );	//将单词插入到列表中
tNode *addTree( tNode *treeNode, char *word );

int main( void )
{
sList	*treeList = NULL;
char	line[ MAXLINE ];
while ( NULL != fgets( line, MAXLINE, stdin ) ){
treeList = addList( treeList, line );		//通过回传链表达到修改链表的目的(PS:伟大的the c programming language,以前学习<C和指针>的时候,只会将地址传递进去,程序变得非常的难看)
}
printList( treeList );
}

sList *addList( sList *treeList, char *line )
{
char temp[ 128 ];			//这里之所以用到字符串数组而不是用到char *,是因为我们需要改变这个字符串
char tag[ 128 ];
memset( temp, 0, 128 );
memset( tag, 0, 128 );
while ( ( *line != '\n' ) && ( line = getword( line, temp ) ) ){	//之所以要加上*line != '\n',是因为一行结尾的时候,line实际上包含两个字符"\n\0".
strncpy( tag, temp, 2 );
treeList = insertList( treeList, tag, temp );
}

return treeList;
}

char *getword( char *line, char *word )
{
while ( !isalpha( *line ) ){
line++;
}
while ( isalpha( *line ) ){
*word++ = *line++;
}
*word = '\0';
return line;
}

sList *insertList( sList *treeList, char *tag, char *word )
{
int cond;
int	i = 0;
char *tempWord = ( char * )malloc( sizeof( char ) * 128 );		//这里之所以要用一个malloc的变量来存储word,是因为word本身是一个指针,函数外任何一个地方对word的操作均会影响到这里的值.
char *tempTag = ( char * )malloc( sizeof( char ) * 128 );
memset( tempWord, 0, 128 );
memset( tempTag, 0, 128 );

while ( '\0' != *word ){
tempWord[ i++ ] = *word++;
}
tempWord[ i ] = '\0';
i = 0;
while ( '\0' != *tag ){
tempTag[ i++ ] = *tag++;
}
tempTag[ i ] = '\0';
if ( NULL == treeList )
{
tNode *treeNode = ( tNode * )malloc( sizeof( tNode ) );
treeNode->data = tempWord;
treeNode->count = 1;
treeNode->left = treeNode->right = NULL;

treeList = ( sList * )malloc( sizeof( sList ) );
treeList->tag = tempTag;
treeList->data = treeNode;
treeList->left = treeList->right = NULL;
}
else if ( ( cond = strcmp( tempTag, treeList->tag ) ) == 0 ){
}
else if ( cond < 0 ){
treeList->left = insertList( treeList->left, tempTag, tempWord );
}
else{
treeList->right = insertList( treeList->right, tempTag, tempWord );
}

return treeList;
}

tNode *addTree( tNode *treeNode, char *word )
{
int cond;

if ( NULL == treeNode ){
treeNode = ( tNode * )malloc( sizeof( tNode ) );
treeNode->data = word;
treeNode->count = 1;
treeNode->left = treeNode->right = NULL;
}
else if ( ( cond = strcmp( word, treeNode->data ) ) == 0 ){
treeNode->count++;
}
else if ( cond < 0 ){
treeNode->left = addTree( treeNode->left, word );
}
else{
treeNode->right = addTree( treeNode->right, word );
}

return treeNode;
}

void printList( sList *treeList )
{
if ( NULL != treeList ){
printList( treeList->left );
printNode( treeList->data );
printList( treeList->right );
}
}

void printNode( tNode *treeNode )
{
if ( NULL != treeNode ){
printNode( treeNode->left );
printf("%s occures %d\n", treeNode->data, treeNode->count );
printNode( treeNode->right );
}
}``````

``````#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAXLINE	1000

struct WORD;
typedef struct LINELIST{
int		lineNum;
struct	WORDTREE	*word;
struct	LINELIST	*next;
}lineList;

typedef struct WORDTREE{
char	*word;
struct	LINELIST	*lineNum;
struct	WORDTREE	*left;
struct	WORDTREE	*right;
} wordTree;

lineList *insertTreeList( lineList *lList, int lineNumber );
wordTree *insertTree( wordTree *wTree, char *word, int lineNumber );
wordTree *insertListTree( wordTree *wTree, char *word );
lineList *insertList( lineList *lList, char *word, int lineNumber );
char *getword( char *line, char *word );
void printList( lineList *lList );
void printTree( wordTree *wTree );
void printListTree( wordTree *wTree );
void printTreeNode( lineList *lList );

int main( void )
{
char	*line = ( char * )malloc( sizeof( char ) * MAXLINE );
char	temp[ MAXLINE ];
int		lineNumber = 0;
wordTree	*wTree = NULL;
lineList	*lList = NULL;
memset( line, 0, MAXLINE );
memset( temp, 0, MAXLINE );

while ( NULL != fgets( line, MAXLINE, stdin ) ){
lineNumber++;
while ( ( *line != '\n' ) && ( line = getword( line, temp ) ) ){
int		i = 0;
char	*tempWord = ( char * )malloc( sizeof( char ) * MAXLINE );
memset( tempWord, 0, MAXLINE );
while ( '\0' != temp[ i ] ){
tempWord[ i ] = temp[ i ];
i++;
}
tempWord[ i ] = '\0';

wTree = insertTree( wTree, tempWord, lineNumber );
lList = insertList( lList, tempWord, lineNumber );
}
}

printTree( wTree );
printf("\n------------\n");
printList( lList );

return 0;
}

char *getword( char *line, char *word )
{
while ( !isalpha( *line ) ){
line++;
}
while ( isalpha( *line ) ){
*word++ = *line++;
}
*word = '\0';
while ( isspace( *line ) && '\n' != *line ){		//省略换行符前面的空格
line++;
}
return line;
}

wordTree *insertTree( wordTree *wTree, char *word, int lineNumber )
{
int cond;
if ( NULL == wTree )
{
wTree = ( wordTree * )malloc( sizeof( wordTree ) );
wTree->word = word;
wTree->left = wTree->right = NULL;
wTree->lineNum = NULL;
wTree->lineNum = insertTreeList( wTree->lineNum, lineNumber );
}
else if ( ( cond = strcmp( word, wTree->word ) ) == 0 ){
wTree->lineNum = insertTreeList( wTree->lineNum, lineNumber );
}
else if ( cond < 0 ){
wTree->left = insertTree( wTree->left, word, lineNumber );
}
else{
wTree->right = insertTree( wTree->right, word, lineNumber );
}

return wTree;
}

lineList *insertTreeList( lineList *lList, int lineNumber )
{
if ( NULL == lList ){
lList = ( lineList * )malloc( sizeof( lineList ) );
lList->lineNum = lineNumber;
lList->next = NULL;
lList->word = NULL;
}
else{
lineList *newNode = ( lineList * )malloc( sizeof( lineList ) );
newNode->lineNum = lineNumber;
newNode->word = NULL;
newNode->next = lList;
lList = newNode;
}

return lList;
}

void printTree( wordTree *wTree )
{
if ( NULL != wTree ){
printTree( wTree->left );
printf("%s : ", wTree->word );
printTreeNode( wTree->lineNum );
printTree( wTree->right );
}
}

void printTreeNode( lineList *lList )
{
while ( NULL != lList ){
printf("%3d ", lList->lineNum );
lList = lList->next;
}
printf("\n");
}

lineList *insertList( lineList *lList, char *word, int lineNumber )
{
if ( NULL == lList ){
lList = ( lineList * )malloc( sizeof( lineList ) );
lList->lineNum = lineNumber;
lList->next = NULL;
lList->word = NULL;
lList->word = insertListTree( lList->word, word );
}
else{
lineList *newnode = ( lineList * )malloc( sizeof( lineList ) );
newnode->lineNum = lineNumber;
newnode->word = NULL;
newnode->word = insertListTree( newnode->word, word );
newnode->next = lList;
lList = newnode;
}

return lList;
}
wordTree *insertListTree( wordTree *wTree, char *word )
{
int cond;
if ( NULL == wTree ){
wTree = ( wordTree * )malloc( sizeof( wordTree ) );
wTree->word = word;
wTree->lineNum = NULL;
wTree->left = wTree->right = NULL;
}
else if ( ( cond = strcmp( word, wTree->word ) ) == 0 ){
return wTree;
}
else if ( cond < 0 ){
wTree->left = insertListTree( wTree->left, word );
}
else{
wTree->right = insertListTree( wTree->right, word );
}

return wTree;
}

void printList( lineList *lList )
{
while ( NULL != lList ){
printf("%d : ", lList->lineNum );
printListTree( lList->word );
printf("\n");
lList = lList->next;
}
}

void printListTree( wordTree *wTree )
{
if ( NULL != wTree ){
printListTree( wTree->left );
printf("%s ", wTree->word );
printListTree( wTree->right );
}
}``````

``````#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAXLINE 128
typedef struct WORDTREE{
char	*word;
int		count;
struct	WORDTREE	*left;
struct  WORDTREE	*right;
}wordTree;

char *getword( char *line, char *word );
wordTree *addTree( wordTree *wTree, char *word );
void printTree( wordTree *wTree );
wordTree *sortTreeNode( wordTree *wTree );
wordTree *insertTree( wordTree *sortTree, wordTree *wTree );

int main( void )
{
wordTree *wTree = NULL;
wordTree *sortTree = NULL;	//用于排序
char	*line = ( char * )malloc( sizeof( char ) * MAXLINE );
char	*word = ( char * )malloc( sizeof( char ) * MAXLINE );
memset( line, 0, MAXLINE );
memset( word, 0, MAXLINE );

while ( NULL != fgets( line, MAXLINE, stdin ) ){
while ( ( *line != '\n' ) && ( line = getword( line, word ) ) ){
int		i = 0;
char	*tempWord = ( char * )malloc( sizeof( char ) * MAXLINE );
memset( tempWord, 0, MAXLINE );
while ( '\0' != *word ){
tempWord[ i++ ] = *word++;
}
tempWord[ i ] = '\0';
wTree = addTree( wTree, tempWord );
}
}

printTree( wTree );
sortTree = sortTreeNode( wTree );
printf("\n------------\n");
printTree( sortTree );

return 0;
}

char *getword( char *line, char *word )
{
while ( !isalpha( *line ) ){
line++;
}
while ( isalpha( *line ) ){
*word++ = *line++;
}
while ( isspace( *line ) && '\n' != *line ){
line++;
}

return line;
}

wordTree *addTree( wordTree *wTree, char *word )
{
int cond;
if ( NULL == wTree ){
wTree = ( wordTree * )malloc( sizeof( wordTree ) );
wTree->count = 1;
wTree->word = word;
wTree->left = wTree->right = NULL;
}
else if ( ( cond = strcmp( word, wTree->word ) ) == 0 ){
wTree->count++;
}
else if ( cond < 0 ){
wTree->left = addTree( wTree->left, word );
}
else{
wTree->right = addTree( wTree->right, word );
}

return wTree;
}

void printTree( wordTree *wTree )
{
if ( NULL != wTree ){
printTree( wTree->left );
printf("%s : %d\n", wTree->word, wTree->count );
printTree( wTree->right );
}
}

wordTree *sortTreeNode( wordTree *wTree )
{
static wordTree *sortTree = NULL;
if ( NULL != wTree ){
sortTreeNode( wTree->left );
sortTree = insertTree( sortTree, wTree );
sortTreeNode( wTree->right );
}

return sortTree;
}

wordTree *insertTree( wordTree *sortTree, wordTree *wTree )
{
if ( NULL == sortTree ){
sortTree = ( wordTree * )malloc( sizeof( wordTree ) );
sortTree->count = wTree->count;
sortTree->word = wTree->word;
sortTree->left = sortTree->right = NULL;
}
else if ( wTree->count <= sortTree->count ){
sortTree->left = insertTree( sortTree->left, wTree );
}
else{
sortTree->right = insertTree( sortTree->right, wTree );
}

return sortTree;
}``````

6.6 表查询

``#define IN 1``

``state = IN;``

``````struct nlist{		/* 链表项 */
struct nlist *next;	/* 链表中下一表项 */
char *name;		/* 定义的名字 */
char *defn;		/* 替换文本 */
};``````

``````#define HASHSIZE 101
static struct nlist *hashtab[ HASHSIZE ];``````

``````unsigned hash( char *s )
{
unsigned hashval;

for ( hashval = 0; *s != '\0'; s++ ){
hashval = *s + 31 * hashval;
}

return hashval % HASHSIZE;
}``````
lookup(s)函数在表中查找s,若找到,则返回指向该处的指针;若没找到,则返回NULL.
``````struct nlist *lookup( char *s )
{
struct nlist *np;

for ( np = hashtab[ hash( s ) ]; np != NULL; np = np->next ){
if ( strcmp( s, np->name ) == 0 ){
return np;
}
}

return NULL;
}``````
install函数借助lookup函数判断加入的名字是否已经存在.如果已存在,则用新的定义取而代之;否则,创建一个新表项.如无足够空间创建新表项,则install函数返回NULL.
``````char *strdup( char * );
struct nlist *install( char *name, char *defn )
{
struct nlist *np;
unsigned hashval;

if ( ( np = lookup( name ) ) == NULL ){
np = ( struct nlist * )malloc( sizeof( *np ) );
if ( np == NULL || ( np->name = strdup( name ) ) == NULL ){
return NULL;
}
hashval = hash( name );
np->next = hashtab[ hashval ];
hashtab[ hashval ] = np;
}
else{
free( ( void * )np->defn );
}

if ( ( np->defn = strdup( defn ) ) == NULL ){
return NULL;
}

return np;
}``````

``````void undef( char *s )
{
int h;
struct nlist *prev, *np;

prev = NULL;
h = hash( s );
for ( np = hashtab[ h ]; np != NULL; np = np->next ){
if ( strcmp( s, np->name ) == 0 ){
break;
}
prev = np;
}
if ( np != NULL ){
if ( prev == NULL ){
hashtab[ h ] = np->next;
}
else{
prev->next = np->next;
}
free( ( void * )np->name );
free( ( void * )np->defn );
free( ( void * )np );
}
}``````

``````#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define MAXWORD 100

struct nlist{
struct nlist *next;
char *name;
char *defn;
};

void error( int, char * );
int getch( void );
void getdef( void );
int getword( char *, int );
struct nlist *install( char *, char * );
struct nlist *lookup( char * );
void skipblanks( void );
void undef( char * );
void ungetch( int );
void ungets( char * );

int main( void )
{
char w[ MAXWORD ];
struct nlist *p;

while ( getword( w, MAXWORD ) != EOF ){
if ( strcmp( w, "#" ) == 0 ){
getdef();
}
else if ( !isalpha( w[ 0 ] ) ){
printf("%s", w );
}
else if ( ( p = lookup( w ) ) == NULL ){
printf("%s", w );
}
else{
ungets( p->defn );
}
}

return 0;
}

void getdef( void )
{
int c, i;
char def[ MAXWORD ], dir[ MAXWORD ], name[ MAXWORD ];

skipblanks();

if ( !isalpha( getword( dir, MAXWORD ) ) ){
error( dir[ 0 ], "getdef:expecting a directive after #" );
}
else if ( strcmp( dir, "define" ) == 0 ){
skipblanks();
if ( !isalpha( getword( name, MAXWORD ) ) ){
error( dir[ 0 ], "getdef:non-alpha -name expected" );
}
else{
skipblanks();
for ( i = 0; i < MAXWORD - 1; i++ ){
if ( ( def[ i ] = getch() ) == EOF || def[ i ] == '\n' ){
break;
}
}
def[ i ] = '\0';
if ( i <= 0 ){
error( '\n', "getdef: incomplete define" );
}
else{
install( name, def );
}
}
}
else if ( strcmp( dir, "undef" ) == 0 ){
skipblanks();
if ( !isalpha( getword( name, MAXWORD ) ) ){
error( name[ 0 ], "getdef:non-alpha in undef" );
}
else{
undef( name );
}
}
else{
error( dir[ 0 ], "getdef:expecting a directive after #" );
}
}

void error( int c, char *s )
{
printf("error:%s\n", s );
while ( c != EOF && c != '\n' ){
c = getch();
}
}

void skipblanks( void )
{
int c;

while ( ( c = getch() ) == ' ' || c == '\t' ){
;
}
ungetch( c );
}``````

6.7 类型定义

C语言提供了一个称为typedef的功能,它用来建立新的数据类型名:

``````typedef struct WORDTREE{
char	*word;
int	count;
struct	WORDTREE	*left;
struct  WORDTREE	*right;
}wordTree;``````

``typedef int ( *PFI )( char *, char * );``

typedef有两个重要的原因:首先,它可以使程序参数化,以提高程序的可移植性.其次为程序提供更好的说明性.

6.8 联合

``````struct{
char *name;
int flags;
int utype;
union{
int ival;
float fval;
char *sval;
} u;
} symtab[ NSYM];``````

``````symtab[ i ].u.ival;
symtab[ i ].u.sval;
symtab[ i ].u.sval[ 0 ];``````

6.9 位字段

``````#define KEYWORD		01
#define EXTERNAL	02
#define STATIC		04

flags |= EXTERNAL | STATIC;
flags &= ~( EXTERNAL | STATIC );``````

``````struct {
unsigned int is_keyword     : 1;
unsigned int is_extern      : 1;
unsigned int is_static      : 1;
} flags;``````

``````flags.is_extern = flags.is_static = 1;
flags.is_extern = flags.is_static = 0;``````

### fzyz_sb

Elements of Programming：追溯数学原理，探求编程的本质

《编程原本》预订网址【互动网】【当当网】【卓越网】【京东网】 《编程原本》（Elements of Programming）前言 《编程原本》将演绎方法应用于程序 设计，讨论程序与保证它们能正确工作的抽象...

2011/12/26
0
0

modernizr
2014/05/22
28.1K
13

2016/02/04
107
2

C语言是面向过程的，而C＋＋是面向对象的 C和C++的区别： C是一个结构化语言，它的重点在于算法和数据结构。C程序的设计首要考虑的是如何通过一个过程，对输入（或环境条件）进行运算处理得到...

2017/12/28
0
0

dragonscroll
2017/11/16
0
0

TypeScript基础入门之高级类型的字符串字面量类型

durban
24分钟前
2
0
iOS权限授权添加

<!-- 相册 --> <key>NSPhotoLibraryUsageDescription</key> <string>App需要您的同意,才能访问相册</string> <!-- 相册写入 --> <key>NSPhotoLibraryAddUsageDescription</key> <string>App......

RainOrz
28分钟前
1
0

MAT中的支配树 在使用MAT分析项目的内存泄漏问题时，其中有一个支配树（Dominator）视图。如果我们把Java对象之间的引用关系看做一张有向图（可以存在环）的话，对象的支配树体现了对象之间的...

akane_oimo
30分钟前
1
0
xshell官网下载及安装（免费版本）

35分钟前
2
0
Android 调用系统分享文字、图片、文件，可直达微信、朋友圈、QQ、QQ空间、微博

36分钟前
3
0