June 30, 2010
For example, 10 (decimal) are all 00001010;
But -10(decimal):
true code:10001010 ('+' is 0, '-' is 1)
complemental code:11110101 sign bit doesn't change, rest all of bits ~
two's complemental code:11110110 base on complemental code plus 1
June 28, 2010
June 27, 2010
need to write something down.
2nd, to do
make file of the project, need a review of oop244.
new phase of the edit project
June 26, 2010
a nice place to review bit operation
one of my classmates did a well job on the bit operation, simply link to his blog as my reference
June 07, 2010
MemCpy()
{
__asm{
mov edi, pDest;
mov esi, pSrc;
mov ecx, iCount;
rep movsb;
}
}
云风的《游戏编程感悟》一书曾提到这个,里面说,64KB的内存拷贝是快不过 memcpy 的,因为VC中,memcpy 并是当做一个函数来编译的, 也就是说编程器会特别照顾 memcpy
June 06, 2010
dumpHexa(&x, sizeof x);------------------------------------------------------------------
putchar('\n');
return 0;
}
/* Dump the first n bytes to the address a */
void dumpHexa(void *a, int n) {
int i;
unsigned char *c = (unsigned char *)a;
for (i = 0; i < n; i++)
printf("%02x ", c[i]);
}
Synonym Pointer Types
Synonym pointer types simplify pointer definitions.
For example, let us define a synonym for a pointer to an int
typedef int * Pint;
We can then define several pointer variables without having to include the * before each identifier
Pint px, py; |
Note that this is more readable than the alternative primitive definition
int* px,* py;------------------------------------------------------IEEE 754
1,8,23 or 1,23,8 for double, long .
1.52,11 or 1,11,52 for long long.
Local Duration
A function parameter or a variable that is defined within a block has local extent unless otherwise specified. Its lifetime lasts from its definition until the closing brace of the block that contains that definition.
There are two distinct usages of local types:
- normal
- very frequent
For normal usage, we may add the keyword auto (for automatic) to the definition
auto int local = 2; |
Since this is the default for any function parameter or any variable defined within a block, we seldom see this keyword in practice.
For very frequent usage, we add the keyword register to the definition
register int local = 2; |
This keyword informs the compiler that the local variable should, if possible, remain in a CPU register as long as necessary. However, since the number of registers is extremely limited, the compiler might not implement such a request.
Internal Linkage
A variable of static duration with internal linkage is invisible outside its own module. To identify internal linkage, we add the keyword static to the definition
static int local = 2;
/* Internal Linkage
* static.c
* May 12 2007
*/
#include
void display() {
static int local = 0;
printf("local is %d\n", local++);
}
int main(void) {
display();
display();
return 0;
}
local is 0
local is 1
Size of
The sizeof() operator evaluates to the size of a type in bytes. The sizeof operator (without the parentheses) evaluates to the size of a variable, object or expression in bytes. For example,
/* Type Sizes |
|
Note that sizeof() takes a type, while sizeof takes a variable, object or expression. With some compilers, the two operators are interchangeable.
int type
An int type occupies one word of memory. One word is typically the size of a CPU register, making the int type the optimally efficient type. On 32-bit platforms, one word spans 4 bytes:
June 02, 2010
echo %errorlevel%
int d=foo();
return d;
------------------------------------------
int a[10] = {1,4,8,56,4,8,3,8,5,3};
int n = 0, i;
for(i=0;i<10;i++){ i="0;i<10;i++){">
int main(void){
int a = 5, b = 6;
if(b > 7 && (a = a + 1)){
printf("X\n");
}
printf("%d\n", a);/* 5 since b >7 is false */
getchar();
return 0;
}
--------------------------------------------
#include
int main(void){
int a[10]={1,4,9,0,4,6,3,2,5,3};
int i=0;
int j;
for(;i<10;){ i="0,j=" i="0,j=">
int main(void){
int a[5]={10,20,30,40,50};
int* p = &a[0]; //same as below */
printf("%d ", *a);
printf("%d ", *(p+0));
printf("%d ", *(a+1));
p++;
printf("%d ", *(p+2));
printf("%d ", (*p)++);
printf("%d ", *(p+2));
getchar();
return 0;
}
//answer 10 10 20 40 20 40
---------------------------------------------------------
#include
void foo(int** q){
(*q)++;
}
int main(void){
int a[5]={100,200,300,400,500};
int* p = a;
foo(&p);
printf("%d\n", *p);
return 0;
}
// comments **q =&p;
--------------------------------
#define PI 3.14159265 //It works In Borland C, don't work with VC and Lunix C
int main(void){
# ifdef sum
printf("PI is defined\n");
# elif PI == 3.14159265
printf("PI is not defined\n");
# endif
return 0;
}