• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            chenglong7997

            1.軟件p4, vs, vim, cscope. 
            fix step:
            先reproduce
            再確定出現(xiàn)問題的函數(shù),行號(hào)
            分析原因
            fix 


            vs中遠(yuǎn)程調(diào)試,指定ip,port, 同時(shí)在遠(yuǎn)程主機(jī)上要同意遠(yuǎn)程調(diào)試,接受指定user。要保證code與exe文件一致。
            設(shè)定斷點(diǎn),觀察debug輸入,與預(yù)想的有什么不同。觀察bt,thread stack 找到出現(xiàn)問題的函數(shù)或者行號(hào)。

            p4 中的check out, commit, diff, opened, edit, sync命令和作用。
            submit step:merge changlist (from branch) (to branch)
            check diff
            resolve
            make (so make sure the code is right)
            submit (add comments)
            set the bug state in Web

            vim:熟悉了各種命令。

            cscope,ctag:在linux中瀏覽代碼很有用,可以找到function definition, struct definition, calling function, called function. 

            在一個(gè)目錄中建立cscope database, 可以再主目錄建立,之后只在這里使用cscope,就能找到全部引用。

            linux, lib 文件的使用。 有.a 和.o的lib文件。

            2.code style.
            文件命名要有層次感。例如,snape_webserver_msg.c, snape_webserver_thread.c, snape_webserver_log.c, snape_client_msg.c,,,
            函數(shù)命名也要有層次感, 例如,snape_webserver_msg_set_connection(), snape_webserver_thread_create(),snape_client_request_get_pic().
            變量命名也要有層次感和意義。
            出錯(cuò)處理的專門函數(shù)。
            debug level:debug,info, basic, webserver, client,,,

            3.函數(shù)的定義與瀏覽。
            call graph definition.
            函數(shù)名字最好能夠顯示出函數(shù)調(diào)用的graph。
            使用hash table 保存大量類型的數(shù)據(jù)。
            使用內(nèi)容的md5作為這個(gè)內(nèi)容的id,就可以完美配合hash table。

            4.thread, process
            windows 中, object , event, cs
            cs同步速度較快,但是使用cs容易進(jìn)入deadlock狀態(tài)。因?yàn)樵诘却M(jìn)入cs時(shí),無法設(shè)定超時(shí)值。
            互斥對(duì)象與內(nèi)核對(duì)象屬于內(nèi)核對(duì)象,利用內(nèi)核對(duì)象進(jìn)行線程同步,同步速度較慢,但這種方式可在多個(gè)進(jìn)程的各個(gè)對(duì)象之間進(jìn)行同步。
            event分為人工重置與自動(dòng)重置事件,兩者在細(xì)節(jié)上,不同。

            5.cache implementation
            client端可以使用類似os中,cache 與 虛擬內(nèi)存的方法。b_modified表示是否經(jīng)過更改,從而是否需要更新。每次只去拿新的東西。
            而在server端,可以使用內(nèi)容的MD5判斷是否需要處理來到的內(nèi)容,可以用多層次的MD5來更加去improve performance。例如用總體的md5,和各個(gè)部分的md5.
            先判斷總體MD5,如果改變,在去檢查部分md5.如果沒有改變,就整個(gè)都可以丟棄,不去處理。
            design is very important. 代碼的執(zhí)行過程要完全依賴design。

            6.select function
            異步select, 可以讓線程不去busy waiting。
            但是如果需要傳輸內(nèi)容,需要trigger signal,讓它不用等到timeout,就能發(fā)送數(shù)據(jù)。

            7.timestamp/timeout/ ts_diff
            可以用ts_diff去同步時(shí)間。
            使用timeout來防止任意操作的無限制等待
            使用timestamp來決定哪一個(gè)更新。不要用counter。(無法同步,無法控制單一性)

            8.xml api
            在傳送數(shù)據(jù)方面,可以使用xml

            9.performace/memory usage
            mm tools.






























            posted @ 2012-09-02 01:16 Snape 閱讀(1284) | 評(píng)論 (0)編輯 收藏

            Suppose I have the following C code.

            unsigned int u = 1234;
            int i = -5678;

            unsigned int result = u + i;

            What implicit conversions are going on here, and is this code safe for all values of u and i? (Safe, in the sense that even though result in this example will overflow to some huge positive number, I could cast it back to an int and get the real result.)

            Answer:

            Short Answer

            Your i will be converted to an unsigned integer by adding UINT_MAX + 1, then the addition will be carried out with the unsigned values, resulting in a large result (depending on the values of u andi).

            Long Answer

            According to the C99 Standard:

            6.3.1.8 Usual arithmetic conversions

            1. If both operands have the same type, then no further conversion is needed.
            2. Otherwise, if both operands have signed integer types or both have unsigned integer types, the operand with the type of lesser integer conversion rank is converted to the type of the operand with greater rank.
            3. Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type.
            4. Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, then the operand with unsigned integer type is converted to the type of the operand with signed integer type.
            5. Otherwise, both operands are converted to the unsigned integer type corresponding to the type of the operand with signed integer type.

            In your case, we have one unsigned int (u) and signed int (i). Referring to (3) above, since both operands have the same rank, your i will need to be converted to an unsigned integer.

            6.3.1.3 Signed and unsigned integers

            1. When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.
            2. Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.
            3. Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.

            Now we need to refer to (2) above. Your i will be converted to an unsigned value by adding UINT_MAX + 1. So the result will depend on how UINT_MAX is defined on your implementation. It will be large, but it will not overflow, because:

            6.2.5 (9)

            A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.

            Bonus: Arithmetic Conversion Semi-WTF

            #include <stdio.h>

            int main(void)
            {
             
            unsigned int plus_one = 1;
             
            int minus_one = -1;

             
            if(plus_one < minus_one)
                printf
            ("1 < -1");
             
            else
                printf
            ("boring");

             
            return 0;
            }

            You can use this link to try this online: http://codepad.org/yPhYCMFO

            Bonus: Arithmetic Conversion Side Effect

            Arithmetic conversion rules can be used to get the value of UINT_MAX by initializing an unsigned value to -1, ie:

            unsigned int umax = -1; // umax set to UINT_MAX

            This is guaranteed to be portable regardless of the signed number representation of the system because of the conversion rules described above. See this SO question for more information: Is it safe to use -1 to set all bits to true?

            posted @ 2012-08-17 02:32 Snape 閱讀(793) | 評(píng)論 (0)編輯 收藏
            1.標(biāo)示符名稱的限制

            ANSI C標(biāo)準(zhǔn)只保證了C實(shí)現(xiàn)必須能夠區(qū)別出前6個(gè)字符不同的外部名稱。而且這個(gè)定義中并沒有區(qū)分大寫字母與其對(duì)應(yīng)的小寫字母。
            因此,編寫可移植程序必須小心這一點(diǎn)。

            2.字符是有符號(hào)的整數(shù),還是無符號(hào)的整數(shù)
            只有把一個(gè)字符值轉(zhuǎn)換為一個(gè)較大的整數(shù)時(shí),才重要。在其他情況下,結(jié)果都是:多余的位被簡(jiǎn)單的“丟棄”。

            在轉(zhuǎn)換過程中:應(yīng)該將字符作為有符號(hào)數(shù)還是無符號(hào)數(shù)?
            如果有符號(hào),編譯器將char數(shù)據(jù),擴(kuò)展到int時(shí)候,應(yīng)該復(fù)制符號(hào)位。
            如果無符號(hào),編譯器只需在多余的位上填充0.
            #include <stdio.h>

            int main()
            {
                char c='a';
                c=c+40;
            //    printf("%c\n", -1); 
                printf("c %d\n", c);
                printf("unsigned c %u\n", (unsigned char)c);
            }
            結(jié)果:
            c -119
            unsigned c 137
            說明在gcc中,將char當(dāng)做有符號(hào)數(shù)。在c+40的時(shí)候,超過了-128~127范圍,因此溢出。如果是無符號(hào)char,范圍是0~255.應(yīng)該是輸出137.

            如果編程者關(guān)注一個(gè)最高位是1的字符是正還是負(fù),可以設(shè)置為無符號(hào)字符數(shù)。這樣所有編譯器都會(huì)轉(zhuǎn)換為整數(shù)時(shí)候,填充為0.


            3.一個(gè)常見錯(cuò)誤是:如果c是一個(gè)字符變量,使用(unsigned)c可以得到與c等價(jià)的無符號(hào)整數(shù)。這是會(huì)失敗的。因?yàn)樵趯轉(zhuǎn)換為無符號(hào)整數(shù)時(shí)候,c將首先首先被轉(zhuǎn)換為int型整數(shù)。而此時(shí)可能得到非預(yù)期的結(jié)果。
            正確方法是:(unsigned char )c,直接進(jìn)行轉(zhuǎn)換。

            例如上個(gè)例子中,最后一句改為:
            printf("unsigned c %u\n", (unsigned )c);

            那么結(jié)果是:
            c -119
            unsigned c 4294967177
            c被先轉(zhuǎn)換為int型-119,再求他的無符號(hào)表達(dá)形式,4294967177 

            4.移位運(yùn)算符
               1.向右移位時(shí),空出的位由0填充,還是由符號(hào)位的副本填充。
               2.如果是無符號(hào)數(shù),用0填充。如果是有符號(hào)數(shù),既可以用0也可以用符號(hào)位的副本。(如果關(guān)注右移時(shí)候空出的位,可以聲明為無符號(hào)類型,那么空出的位都會(huì)被設(shè)置為0)

               如果被移位對(duì)象為n位,那么移位計(jì)數(shù)必須大于或等于0,而嚴(yán)格小于n.
            即使C實(shí)現(xiàn)將符號(hào)位復(fù)制到空出的位中,有符號(hào)數(shù)的向右移位,也并不等于除以2的某次冪。例如(-1)>>1結(jié)果為-1,而不是-1/2 == 0

            5.隨機(jī)數(shù)最大值,RAND_MAX在limits中定義。我測(cè)試結(jié)果等于INT_MAX

            6.除法運(yùn)算的截?cái)?br />q=a/b;
            r=a%b;
            假定b>0.
            C語言定義只保證q*b+r=a,以及a>=0 且 b>0時(shí),保證|r|<|b|以及r>=0.
            (如果a<0, 那么r也可能小于0)
            例如:
            int main() {
                // Start typing your code here
                
                cout<<(-3)/2<<endl;
                return 0;
            }
            結(jié)果商為-1,余數(shù)也為-1
            posted @ 2012-06-25 07:10 Snape 閱讀(318) | 評(píng)論 (0)編輯 收藏
            使用預(yù)處理器的兩個(gè)主要原因:
            1.一次修改變量,出現(xiàn)的所有的值都會(huì)修改。
            講所有常量定義集中在一起。

            2.避免函數(shù)調(diào)用開銷。

            3.宏定義注意點(diǎn)
                1.不能忽視定義中的空格
                2.最好將宏定義中每個(gè)參數(shù)都用括號(hào)括起來。整個(gè)表達(dá)式的結(jié)果頁(yè)用括號(hào)括起來。
                3.確保調(diào)用宏的參數(shù)中,不存在有副作用的代碼

            4.assert宏。可以在出錯(cuò)信息中包含文件名和斷言失敗處的行號(hào)。很有用。

            5.宏并不是類型定義。
            #define T1 struct foo *
            typedef struct foo * T2;
            T1 a,b; //struct foo * a, b;
            T2 a,b; //a ,b都是指向結(jié)構(gòu)的指針。
            posted @ 2012-06-25 02:26 Snape 閱讀(249) | 評(píng)論 (0)編輯 收藏
            1.getchar

            getchar返回整形

            #include <stdio.h>

            int main()
            {
                char c;
                while( (c=getchar())!=EOF )
                    putchar(c);
            }

            應(yīng)該將c聲明為int。否則,c可能無法容下EOF

            2.更新文件
            讀操作之后,文件指針會(huì)偏移一段。這時(shí)候,講文件更新后,寫入源文件之前,應(yīng)該fseek講文件指針調(diào)回去。

            3.使用setbuf設(shè)置輸出的緩沖區(qū)大小??梢允莝tdout和file

            4.正確使用errno檢測(cè)錯(cuò)誤
            errno=0;
            /*調(diào)用庫(kù)函數(shù)*/
            if(返回的錯(cuò)誤值)   //這個(gè)錯(cuò)誤值可能不是由當(dāng)前這個(gè)函數(shù)引起的。而是由當(dāng)前函數(shù),又調(diào)用的另外一個(gè)函數(shù)引起的。
               檢查errno;

            5.signal處理函數(shù)唯一安全,可移植的操作就是打印一條錯(cuò)誤信息,然后使用longjmp或者exit立即退出程序。
            posted @ 2012-06-25 02:10 Snape 閱讀(304) | 評(píng)論 (0)編輯 收藏
            1.如果一個(gè)函數(shù)僅僅被同一個(gè)源文件中的其他函數(shù)調(diào)用,我們就應(yīng)該聲明該函數(shù)為static

            2.extern int n;
            在兩外一個(gè)文件中: long n;
            這是一個(gè)無效的程序,因?yàn)橥粋€(gè)外部變量名在兩個(gè)不同的文件中被聲明為不同的類型。然后大多數(shù)c語言實(shí)現(xiàn)不能檢測(cè)出這種錯(cuò)誤。

            3.一個(gè)程序由多個(gè)模塊組成,每個(gè)模塊都需要知道一個(gè)特定的文件名。我們希望能夠做到只在一處改動(dòng)這個(gè)文件名,所有模塊中的文件名就能同時(shí)得到更新。
            可以,先創(chuàng)建一個(gè)文件,叫做file.h,它包含了聲明extern char filename[];
            需要用到外部對(duì)象filename的每個(gè)c源文件都應(yīng)該加上: #include "file.h";
            最后選擇一個(gè)C源文件,在其中給出filename的初始值。如在file.c中
            #include "file.h";
            char filename[]="/etc/passwd";

            這樣就保證了filename的類型是正確的。解決了2中的問題。
            posted @ 2012-06-25 01:41 Snape 閱讀(241) | 評(píng)論 (0)編輯 收藏

             整數(shù)溢出
            c語言中存在兩類整數(shù)算術(shù)運(yùn)算,有符號(hào)運(yùn)算和無符號(hào)運(yùn)算。在無符號(hào)運(yùn)算里,沒有了符號(hào)位,所以是沒有溢出的概念的。

            所有的無符號(hào)運(yùn)算都是以2的n次方為模。如果算術(shù)運(yùn)算符的一個(gè)操作數(shù)是有符號(hào)書,另一個(gè)是無符號(hào)數(shù),那么有符號(hào)數(shù)

            會(huì)被轉(zhuǎn)換為無符號(hào)數(shù)(表示范圍小的總是被轉(zhuǎn)換為表示范圍大的),那么溢出也不會(huì)發(fā)生。但是,當(dāng)兩個(gè)操作數(shù)都是有符號(hào)數(shù)

            時(shí),溢出就有可能發(fā)生。而且溢出的結(jié)果是未定義的。當(dāng)一個(gè)運(yùn)算的結(jié)果發(fā)生溢出時(shí),任何假設(shè)都是不安全的。

            例如,假定a和b是兩個(gè)非負(fù)的整型變量(有符號(hào)),我們需要檢查a+b是否溢出,一種想當(dāng)然的方式是:

            if (a + b < 0)

                  溢出;

            實(shí)際上,在現(xiàn)實(shí)世界里,這并不能正常運(yùn)行。當(dāng)a+b確實(shí)發(fā)生溢出時(shí),所有關(guān)于結(jié)果如何的假設(shè)均不可靠。比如,在某些

            機(jī)器的cpu,加法運(yùn)算將設(shè)置一個(gè)內(nèi)部寄存器為四種狀態(tài):正,負(fù),零和溢出。在這種機(jī)器上,c編譯器完全有理由實(shí)現(xiàn)以上

            的例子,使得a+b返回的不是負(fù),而是這個(gè)內(nèi)存寄存器的溢出狀態(tài)。顯然,if的判斷會(huì)失敗。

            一種正確的方式是將a和b都強(qiáng)制轉(zhuǎn)換為無符號(hào)整數(shù):

            if ( (unsigned)a + (unsigned)b  > INT_MAX)

                  溢出;

            這里的int_max值為有符號(hào)整型的最大值。在一般的編譯器里是一個(gè)預(yù)定義的常量。ANSI C在limits里定義了INT_MAX,值為

            2的31次方-1.

            不需要用到無符號(hào)算數(shù)運(yùn)算的另一種可行方法是:

            if (a > INT_MAX - b )

                 溢出; 

            posted @ 2012-06-25 01:15 Snape 閱讀(996) | 評(píng)論 (0)編輯 收藏

            posted @ 2012-06-25 01:11 Snape 閱讀(429) | 評(píng)論 (0)編輯 收藏
            1.int a[10]; 除了a被用作運(yùn)算符sizeof()的參數(shù)這一情況,在其他所有的情形中,數(shù)組名a都代表指向數(shù)組a中下標(biāo)為0的元素的指針。
            因此,int *p=a; //right
            int  *p=&a; //error, (&a已經(jīng)是一個(gè)指向整個(gè)數(shù)組的指針)

            2.為main函數(shù)提供返回值
            main()
            {}
            隱含著main返回整數(shù),一個(gè)返回整數(shù)的函數(shù)如果返回失敗,實(shí)際上隱含返回某個(gè)“垃圾”整數(shù),只要該值不被用到,就無關(guān)緊要。
            然而,在某些情況下,main的返回值卻并非無關(guān)緊要,大多數(shù)C語言實(shí)現(xiàn)通過main的返回值,來告知操作系統(tǒng)該函數(shù)的執(zhí)行是成功還是失。如果一個(gè)程序的main函數(shù)并不返回任何值,那么有可能看上去執(zhí)行失敗。所以最好提供返回值

            3.邊界計(jì)算與不對(duì)稱邊界。
            適合c中以下標(biāo)為0開始的計(jì)算。
            posted @ 2012-06-24 23:53 Snape 閱讀(304) | 評(píng)論 (0)編輯 收藏
            1.y=x/*p;   //p指向除數(shù)
            error.
            /*會(huì)被當(dāng)做注釋的開始。應(yīng)該y=x / *p;
            或者y = x/(*p); 

            2.如果一個(gè)整形常量第一個(gè)字符為數(shù)字0.那么這個(gè)常量會(huì)被當(dāng)做8進(jìn)制數(shù)。
            posted @ 2012-06-23 06:21 Snape 閱讀(200) | 評(píng)論 (0)編輯 收藏
            僅列出標(biāo)題
            共2頁(yè): 1 2 

            導(dǎo)航

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            my

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            国产精品免费久久| 久久精品国产亚洲AV麻豆网站| 亚洲国产精品人久久| 国产福利电影一区二区三区,免费久久久久久久精 | 久久国产精品免费| 久久99精品久久久久久水蜜桃| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久精品国产第一区二区三区| www.久久热| 久久亚洲AV无码西西人体| 中文字幕久久波多野结衣av| 久久久久久免费一区二区三区| 亚洲国产精品成人AV无码久久综合影院| 久久久久亚洲国产| 91久久精一区二区三区大全| 日韩精品无码久久一区二区三| 久久精品中文闷骚内射| 亚洲国产高清精品线久久| 亚洲午夜精品久久久久久人妖| 国产偷久久久精品专区| 久久狠狠一本精品综合网| 久久精品国产久精国产思思| 久久精品免费一区二区| 久久精品女人天堂AV麻| 国产精品美女久久久m| 久久精品国产亚洲AV影院| 久久综合亚洲色HEZYO国产| 国产精品久久久久9999高清| 97久久国产露脸精品国产| 国产精品久久久久久五月尺| 91精品国产91热久久久久福利| 久久免费高清视频| 九九久久自然熟的香蕉图片| 久久久久久久久久久久久久| 香港aa三级久久三级老师2021国产三级精品三级在 | 亚洲国产精品人久久| 国产∨亚洲V天堂无码久久久| 亚洲中文字幕无码久久综合网| 四虎国产精品成人免费久久| 一本色综合久久| 亚洲AV无码久久寂寞少妇|