我想知道是否存在以下区别:
我还想知道是否有充分的理由使用(2)超过(1).我在遗留代码中看到过(2)这就是我想知道的原因.从上下文来看,我无法理解为什么(2)被优先于(1).从我写的下面的测试中,我得出的结论是,至少上传的行为在两种情况下都是相同的:
/* compile with gcc -lm */
#include <stdio.h>
#include <math.h>
int main(void)
{
unsigned max_unsigned = pow(2, 8 * sizeof(unsigned)) - 1;
printf("VALUES:\n");
printf("%u\n", max_unsigned + 1);
printf("%lu\n", (unsigned long)max_unsigned + 1); /* case 1 */
printf("%lu\n", *((unsigned long *)&max_unsigned) + 1); /* case 2 */
printf("SIZES:\n");
printf("%d\n", sizeof(max_unsigned));
printf("%d\n", sizeof((unsigned long)max_unsigned)); /* case 1 */
printf("%d\n", sizeof(*((unsigned long *)&max_unsigned))); /* case 2 */
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
VALUES:
0
4294967296
4294967296
SIZES:
4
8
8 …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一种要传递的格式字符串,git log --pretty以便每个日志条目以完整的提交消息结尾,但每个日志条目都由一个空行分隔。问题在于,有些完整提交消息以换行符结尾,有些则不然。
例如,假设我有两个提交abc1234和def5678,但仅abc1234在完整提交消息的末尾包含换行符。在命令行上输出原始提交内容将如下所示:
[prompt]$ git cat-file commit abc1234
(...)
Title FOO
Full commit message FOO
[prompt]$ git cat-file commit def5678
(...)
Title BAR
Full commit message BAR[prompt]$
Run Code Online (Sandbox Code Playgroud)
请注意新的 shell 提示符如何出现在最后一行输出的末尾,表明提交在完整提交消息的末尾def5678不包含换行符。
假设这def5678是父级abc1234,我想输出一个简单的日志,其中每个条目仅包含短提交哈希、标题行和完整提交消息。我可能会尝试这样的事情:
[prompt]$ git log --graph --pretty='commit %h%n%B' abc1234
* commit abc1234
| Title FOO
|
| Full commit message FOO
|
* commit def5678
| Title BAR
|
| Full commit message …Run Code Online (Sandbox Code Playgroud)