程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 走進C標准庫(7)——"string.h"中函數的實現memcmp,memcpy,memmove,memset

走進C標准庫(7)——"string.h"中函數的實現memcmp,memcpy,memmove,memset

編輯:關於C語言

我的memcmp:

  memcmp( *buf1,  *buf2, unsigned           (count && !(reval = (*(unsigned  *)buf1) - (*(unsigned  *          buf1 = (unsigned  *)buf1 +          buf2 = (unsigned  *)buf2 +          --       }

MS VC:

  *  * (!( ( --count && *( *)buf1 == *( *= ( *)buf1 + = ( *)buf2 + ( *((unsigned  *)buf1) - *((unsigned  *

應該使用const void *buf為宜,不改變該塊內存的內容,最終使用unsigned char *進行運算,保證運算結果的符號正確。

 

我的memcpy:

  *memcpy( *dest,   *src, unsigned       *reval =     (count--          (*(unsigned  *)dest++) = (*(unsigned  *)src++       }

MSVC:

  *          *           *             * ret = 
  defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
            RtlMoveMemory(  *,   * 
     /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
         
           
          (count--                 *( *)dst = *( *                 dst = ( *)dst +                  src = ( *)src +     /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
 
          }

 

我的memmove:

  *memmove( *dest,   *src, unsigned       *reval =      overlap = ((unsigned  *)src < (unsigned  *)dest && ((unsigned  *)src + count) >     (count--         (overlap)
               (*((unsigned  *)dest + count)) = (*((unsigned  *)src + count         
             (*(unsigned  *)dest++) = (*(unsigned  *)src++       }

MSVC:

  *          *           *             * ret = 
  defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
            RtlMoveMemory(  *,   * 
     /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
          (dst <= src || ( *)dst >= (( *)src +                 
                    
                  (count--                         *( *)dst = *( *                         dst = ( *)dst +                          src = ( *)src +                             
                    
                 dst = ( *)dst + count -                  src = ( *)src + count -  
                  (count--                         *( *)dst = *( *                         dst = ( *)dst -                          src = ( *)src -      /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
 
          }

關於memcpy和memmove的區別,memcpy不考慮內存區域重疊的情況而memmove保證內存區域重疊也能正常復制成功。

有時候我們的memcpy也可能在內存重疊的情況下正常使用,這取決於它的實現,不具有普遍性,C語言標准中未對其有這種要求。

參考資料:

《關於memcpy和memmove兩函數的區別》

http://blog.csdn.net/caowei840701/article/details/8491836

《memcpy() vs memmove()》  

http://stackoverflow.com/questions/4415910/memcpy-vs-memmove

 

我的memset:

  *memset( *buffer,  c,       *reval =     (count--         (*(unsigned  *)buffer++) = (unsigned        }

MSVC:

  *          *                      *start = 
  defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC)
            RtlFillMemory(  *, size_t count,  
         RtlFillMemory( dst, count, (    /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
          (count--                 *( *)dst = (                 dst = ( *)dst +     /* defined (_M_MRX000) || defined (_M_ALPHA) || defined (_M_PPC) */
 
          }

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved