Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C “a”是否有特殊含义$&引用;在字符串的末尾做标记?_C - Fatal编程技术网

C “a”是否有特殊含义$&引用;在字符串的末尾做标记?

C “a”是否有特殊含义$&引用;在字符串的末尾做标记?,c,C,请参考我在某个c程序中看到的代码: #define _BUILD_DATE "2010/05/03$" #define _BUILD_TIME "10:46:42$" #define _BUILD_GUEST "Intel$" #define _BUILD_BOARD "B0$" #define _BUILD_CODEVER "2.00$" const unsig

请参考我在某个c程序中看到的代码:

#define _BUILD_DATE     "2010/05/03$" 
#define _BUILD_TIME     "10:46:42$"
#define _BUILD_GUEST    "Intel$"
#define _BUILD_BOARD    "B0$"
#define _BUILD_CODEVER  "2.00$"

const unsigned char SIGN_DATE[] = {_BUILD_DATE};
const unsigned char SIGN_TIME[] = {_BUILD_TIME};
const unsigned char SIGN_GUST[] = {_BUILD_GUEST};
const unsigned char SIGN_PCBV[] = {_BUILD_BOARD};
const unsigned char SIGN_CODEVR[] = {_BUILD_CODEVER};
我很好奇为什么每个字符串的末尾都有一个“$”标记。 首先,我想在声明带有“{”和“}”的字符串后,也许应该遵循这个规则,但下面的测试表明它仍然可以正常工作

#include <stdio.h>
unsigned char A[] = {"ABC$"};
//unsigned char A[] = {"ABC"};
unsigned char B[] = "123";


int main()
{
    int i,j;
    
    for(i=0;i<sizeof(A);i++)
    {
        if(A[i] == '\0')
            printf("null\n");
        else
            printf("%c\n",A[i]);
    }
    printf("\n");
    for(j=0;j<sizeof(B);j++)
    {
        if(B[j] == '\0')
            printf("null\n");
        else
            printf("%c\n",B[j]);
    }
    printf("size of A is %d\n",(int)sizeof(A));
    printf("size of B is %d\n",(int)sizeof(B));

    return 0;
}
#包括
无符号字符A[]={“ABC$”};
//无符号字符A[]={“ABC”};
无符号字符B[]=“123”;
int main()
{
int i,j;
对于(i=0;i
所以我不确定在某些情况下“$”是否有什么特殊意义,或者它只是一个毫无意义的标记

简短回答 它在C语言中没有特殊意义。在核心语言中没有,在任何库函数中也没有约定。库函数将零视为终止符

长话短说 我不能说它在特定的代码中是否有任何意义。这是很可能的。但一般来说,它没有任何特殊的意义。一个猜测是字符串在某个地方被用作正则表达式。然后它就有了意义

但更好的猜测是,这与DOS使用以美元结尾的字符串有关。在DOS中,您可以使用中断9打印以美元结尾的字符串。您的程序可能有一个依赖于此的打印函数。或者可能有某种工具可以分析依赖于此的可执行文件

这是一个使用DOS中断的x86程序集的Hello World

; hello-DOS.asm - single-segment, 16-bit "hello world" program
;
; assemble with "nasm -f bin -o hi.com hello-DOS.asm"

    org  0x100        ; .com files always start 256 bytes into the segment

    ; int 21h is going to want...

    mov  dx, msg      ; the address of or message in dx
    mov  ah, 9        ; ah=9 - "print string" sub-function
    int  0x21         ; call dos services

    mov  ah, 0x4c     ; "terminate program" sub-function
    int  0x21         ; call dos services

    msg  db 'Hello, World!', 0x0d, 0x0a, '$'   ; $-terminated message
请注意,
0x0d,0x0a
仅用于打印换行符。在DOS(以及windows)上,换行符(0a)之前需要回车符(0d)

我在这里找到了密码


在C语言中,字符串的结尾是零终止符。

'$'对C语言编程的字符串操作没有特殊意义。

那么,你在哪里找到了上述代码?它可能在那里有特殊意义,即使它通常不是。一些版本控制系统使用以$分隔的标记,在签出f时,这些标记会被各种值所取代ile(如上次提交日期、提交者id等),但我不熟悉任何在最后只使用一个的。在古代的DOS时代,这就像一个字符串结束标记(或换行符)。@underline\d我在嵌入式系统代码中看到了它们,在代码和文档中都找不到任何相关线索(如其规范和Keil Cx51编译器用户指南)。