和我一起工作的实习生向我展示了他在计算机科学方面考试的关于字节序问题的考试.有一个问题显示ASCII字符串"My-Pizza",学生必须显示该字符串将如何在小端计算机的内存中表示.当然,这听起来像一个技巧问题,因为ASCII字符串不受端序问题的影响.
但令人震惊的是,实习生声称他的教授坚持认为该字符串将表示为:
P-yM azzi
Run Code Online (Sandbox Code Playgroud)
我知道这不可能是正确的.在任何机器上都不能像ASCII字符串那样表示ASCII字符串.但显然,教授坚持这样做.所以,我写了一个小C程序并告诉实习生把它交给他的教授.
#include <string.h>
#include <stdio.h>
int main()
{
const char* s = "My-Pizza";
size_t length = strlen(s);
for (const char* it = s; it < s + length; ++it) {
printf("%p : %c\n", it, *it);
}
}
Run Code Online (Sandbox Code Playgroud)
这清楚地表明字符串在内存中存储为"My-Pizza".一天后,实习生回到我身边,告诉我教授现在声称C正在自动转换地址,以正确的顺序显示字符串.
我告诉他他的教授很疯狂,这显然是错的.但是为了检查我自己的理智,我决定在stackoverflow上发布这个,所以我可以让其他人确认我在说什么.
所以,我问:谁在这里?
首先,什么是M-oM-;M-??
当我将提交推送到 bitbucket 时,有人使用在线编辑器进行小更改,它会将第一行更改为:
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
到:
M-oM-;M-?<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
我可以使用这些特殊字符cat -A <myfile>
这是一个问题,因为这会破坏我的*.csproj文件并且无法在 Visual Studio 中加载项目。
Bitbucket 支持给了我关于.gitattributes和 config 的文章,我已经尝试过,但问题仍然存在:
$ git config core.autocrlf
true
$ cat .gitattributes
*.js text
*.cs text
*.xml text
*.csproj text
*.sln text
*.config text
*.cshtml text
*.json text
*.sql text
*.ts text
*.xaml text
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
$ cat .gitattributes
*.js text eol=crlf
*.cs text eol=crlf
*.xml text eol=crlf
*.csproj text eol=crlf
*.sln text eol=crlf
*.config text …Run Code Online (Sandbox Code Playgroud)