c 字符串函數(shù)

http://c.biancheng.net/c/assert/ good 用斷言來(lái)校驗(yàn) 參數(shù) 所有語(yǔ)言都有的進(jìn)階思想
在函數(shù)中使用斷言來(lái)檢查參數(shù)的合法性
在防錯(cuò)性程序設(shè)計(jì)中使用斷言來(lái)進(jìn)行錯(cuò)誤報(bào)警
在c語(yǔ)言上尤其有用。 因?yàn)閏語(yǔ)言 如果內(nèi)存指針 有點(diǎn)錯(cuò)。或null 或越界。 直接 Segmentation fault 段錯(cuò)誤
用assert 自己報(bào)錯(cuò)。good。 報(bào)錯(cuò)是一個(gè)技術(shù)點(diǎn)。。因?yàn)槌绦蛑械腷ug位置知道。已經(jīng)解決了90%了。

字符串本質(zhì)上是在內(nèi)存地址上順序存放的一組字節(jié) 。

https://zhuanlan.zhihu.com/p/409044316

char *
STRCAT (char *dest, const char *src)
{
  strcpy (dest + strlen (dest), src);
  return dest;
}
libc_hidden_builtin_def (strcat)
char *
STPCPY (char *dest, const char *src)
{
  size_t len = strlen (src);
  return memcpy (dest, src, len + 1) + len;
}
weak_alias (__stpcpy, stpcpy)
libc_hidden_def (__stpcpy)
libc_hidden_builtin_def (stpcpy)
#include <sysdeps/generic/memcopy.h>

#undef  OP_T_THRES
#define OP_T_THRES  8

#undef  BYTE_COPY_FWD
#define BYTE_COPY_FWD(dst_bp, src_bp, nbytes)                     \
  do {                                        \
    int __d0;                                     \
    asm volatile(/* Clear the direction flag, so copying goes forward.  */    \
         "cld\n"                              \
         /* Copy bytes.  */                       \
         "rep\n"                              \
         "movsb" :                            \
         "=D" (dst_bp), "=S" (src_bp), "=c" (__d0) :              \
         "0" (dst_bp), "1" (src_bp), "2" (nbytes) :           \
         "memory");                           \
  } while (0)

#undef  BYTE_COPY_BWD
#define BYTE_COPY_BWD(dst_ep, src_ep, nbytes)                     \
  do                                          \
    {                                         \
      int __d0;                                   \
      asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
           "std\n"                            \
           /* Copy bytes.  */                         \
           "rep\n"                            \
           "movsb\n"                              \
           /* Clear the dir flag.  Convention says it should be 0. */ \
           "cld" :                            \
           "=D" (dst_ep), "=S" (src_ep), "=c" (__d0) :            \
           "0" (dst_ep - 1), "1" (src_ep - 1), "2" (nbytes) :         \
           "memory");                             \
      dst_ep += 1;                                \
      src_ep += 1;                                \
    } while (0)

#undef  WORD_COPY_FWD
#define WORD_COPY_FWD(dst_bp, src_bp, nbytes_left, nbytes)            \
  do                                          \
    {                                         \
      int __d0;                                   \
      asm volatile(/* Clear the direction flag, so copying goes forward.  */  \
           "cld\n"                            \
           /* Copy longwords.  */                     \
           "rep\n"                            \
           "movsl" :                              \
           "=D" (dst_bp), "=S" (src_bp), "=c" (__d0) :            \
           "0" (dst_bp), "1" (src_bp), "2" ((nbytes) / 4) :       \
           "memory");                             \
      (nbytes_left) = (nbytes) % 4;                       \
    } while (0)

#undef  WORD_COPY_BWD
#define WORD_COPY_BWD(dst_ep, src_ep, nbytes_left, nbytes)            \
  do                                          \
    {                                         \
      int __d0;                                   \
      asm volatile(/* Set the direction flag, so copying goes backwards.  */  \
           "std\n"                            \
           /* Copy longwords.  */                     \
           "rep\n"                            \
           "movsl\n"                              \
           /* Clear the dir flag.  Convention says it should be 0. */ \
           "cld" :                            \
           "=D" (dst_ep), "=S" (src_ep), "=c" (__d0) :            \
           "0" (dst_ep - 4), "1" (src_ep - 4), "2" ((nbytes) / 4) :   \
           "memory");                             \
      dst_ep += 4;                                \
      src_ep += 4;                                \
      (nbytes_left) = (nbytes) % 4;                       \
    } while (0)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容