Pages

June 30, 2010

computer stores number on one/two's complemental code method. true code, complemental code and one's complement code of unsigned number are all equel;
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

g++ ioframe_tester.cpp ioframe.cpp -x c iof.c -lncurses
compile c code under c++ compiler

June 27, 2010

need to write something down.

1st, I need to write some important points down during learning.
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

http://yujinjeong.wordpress.com/
one of my classmates did a well job on the bit operation, simply link to his blog as my reference

June 07, 2010

50 rules to learn C++ Language. (I filed it to encourage myself during study C++)

MemCpy()

inline void MemMoveBYTEHelp( char * pDest, char * pSrc, unsigned int iCount )
{
__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
* sizeof.c
* May 14 2007
*/

#include

int main(void) {
double x;
printf("On this machine, \n"
"the size of an int is %d bytes,\n"
"the size of x is %d bytes.\n",
sizeof(int), sizeof x );
return 0;
}










On this machine,
the size of an int is 4 bytes,
the size of x is 8 bytes.




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

A test is going to be taken tomorrow. Follow is my review

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;
}

//Conditional Compilation (#if, #ifdef, #ifndef, #else, #elif, #endif, and defined)

//(#ifdef #undef #endif)

May 20, 2010

Macro

Cited from BTP300 Chris seneca cs Web

  • Continuation
  • A macro definition may extend over several lines. The backslash character - \ - immediately followed by the end-of-line character identifies a continuation onto the next line. For example,

    #define PI 3.141\
    592654
    is the same as
    #define PI 3.141592654

  • Efficiency and Flexibility

    Function-like macros provide efficient and flexible solutions. They avoid the overhead of function calls and do not impose type constraints on the parameters in the macro definition.

  • #define SQUARE(x)  ((x) * (x)) /* NOTE THE PARENTHESES *// Fardad noted in class
  • Side-Effects

    Macro definitions can also generate side effects. Because the pre-processor substitutes textual patterns rather than values, it can generate repeated evaluations of expressions that were intended to be a single evaluation. Such as area(r++).

  •  #define PI 3.14
    #undef PI
    #define PI 3.14159 /* OK */
    #define AREA(r) PI * r * r
  • Predeined macros
  •      printf("The name of the source file is %s\n", __FILE__);
    printf("The date of its translation is %s\n", __DATE__);
    printf("The time of its translation is %s\n", __TIME__);
    if (__STDC__ != 0)
    printf("Compiled under Standard C\n");
    else
    printf("Not compiled under Standard C\n");
reference macro
Cited from course BTP300 , Chris, seneca cs web
  • C and C++ compilers process source code in three distinct stages: pre-processing, compilation proper and linking
  • mixed language program require linkage convention declarations to ensure that the function identifiers used in the definition and in the function call are identical

  • To resolve this incompatibility, we direct the C++ compiler to use the "C" linkage convention in calling hello() rather than the default C++ convention. We do so by wrapping the include directive in a linkage convention declaration:
  •  extern "C" {            /* identifies C linkage convention */
    #include "hello.h"
    }

May 19, 2010

learning steps of SVN

A repository location, however, is always a URL.
Schema Access Method
file:/// direct repository access (on local disk)
http:// access via WebDAV protocol to Subversionaware
Apache server
https:// same as http://, but with SSL encryption.
svn:// access via custom protocol to an svnserve
server
svn+ssh:// same as svn://, but through an SSH tunnel.

C:\> svn checkout file:///X:/path/to/repos

C:\> svn checkout "file:///X|/path/to/repos"


I create a personal Repository on my local disk. It seems pointless to create a personal Repos as long as only me use my pc at beginning, but I think it's still good idea to keep it in case i can trace my history codes even on offline status. It's kind of "Time Machine". I just wonder it is possible to sync one folder to 2 repositories?

May 17, 2010

OOP344

Is Prof. Fardad's oop344 need use brain to get good mark?
The answer is "YES", I guess. I Didn't use my brain for long, it seems stuck right now, not sure how much lube I should fill in to run it smoothly, might it's mission impossible. Well, I will try my best. It's time to warm up.

May 13, 2010

mIRC

WebBased IRC
http://webchat.freenode.net/

the mIRC client supports multi-threads. just right click the mIRC tray icon then click the channel name just above 'exit' it can switch back the channel I want. I cann't switch it back by press alt-tab keys.

register username

/msg nickserv register
  1. To keep your email address private, rather than displaying it publicly, mark it as hidden:
    /msg nickserv set hidemail on
  2. It's useful, but not required, to have an alternate nick grouped to your account. For example, if your primary nick is foo:
    /nick foo_
    and then
    /msg nickserv group
  3. If you're running an older version of xchat and you've requested a cloak, you may need to follow these instructions so that your client will properly identify to Nickserv before joining any channels. Recent versions of xchat appear to handle things just fine.

  4. Configure your client to identify itself to nickserv automatically whenever it connects to freenode so that it's less likely you'll connect to the network without being identified to nickserv. The easiest approach is to specify your nickserv password as a server password.

May 12, 2010

May 12, 2010

My first blog, which will be dedicated to OOP344.

Fardad tries to let his students be familiar with lots of tools to apply in the open source environment. I like the point.

So far I have a personal wiki under the zenit site, a blog at myoop344blog.blogspot.com.

I installed svn client on my pc, and will install one on my mac.

also I have already added my personal information to student list, and my blog to planet CDOT feeder list

installed a mIRC client I can login yesterday but I cann't login today since I tried to register the nicename xlu44 on the freenode irc server.

I set my target on this course is A+.