如何在vim编辑器中的大括号之间显示垂直线.在编写C代码时很有用.
到目前为止,在使用vim编辑器时,如果我想知道右大括号的位置,我会做以下事情:
在正常模式下,我将光标移动到打开括号{,然后按下%光标关闭}.
然后(尝试)记住打开和关闭括号的行号.
但是当我这样做时,我经常会忘记打开和关闭括号的行号.此外,很多时候,支架对是嵌套的,这使得记忆更加困惑.
所以我想在大括号之间绘制一条垂直线,以便我可以执行以下操作:
{并按j或k(或甚至%或任何其他动作命令)来浏览文件.但是左侧增加了一条线,以便我可以知道我在哪个街区.因此,如果代码缩进正确,那么通过查看左侧的行我将始终跟踪我所在的块.并且可以使用j和k(或任何其他运动命令)而不必记住行号打开和关闭支架.
我们怎样才能在vim中做到这一点?
更新:在这里得到答案是否可以在Vim中显示缩进指南?.
假设我有以下规则Makefile.
test.o: test.cpp foo.h
g++ -c -o test.o test.cpp
Run Code Online (Sandbox Code Playgroud)
现在假设foo.h包括bar.h如下所示.
user $ head -n 5 foo.h
#include"bar.h"
/*
.
.
*/
user $
Run Code Online (Sandbox Code Playgroud)
test.o如果有任何变化,是否会再次建造bar.h?
或者我应该bar.h在规则中特别提到如下:
test.o: test.cpp foo.h bar.h
g++ -c -o test.o test.cpp
Run Code Online (Sandbox Code Playgroud) 如果我在C中有以下字符串:
char s[]="Question";
Run Code Online (Sandbox Code Playgroud)
然后我注意到下面的两个prtintf都在终端中正确打印了字符串.
1.
printf("%s\n",s);
Run Code Online (Sandbox Code Playgroud)
2.
printf("%s\n",&s);
Run Code Online (Sandbox Code Playgroud)
这是在C中打印字符串的正确方法.如果两者都相同,那么遵循的约定是什么?1还是2?
谢谢.
我们知道我们可以在Linux中创建硬链接,ln file1 file2这将成为file2一个硬链接file1.
但是,当我尝试使用C程序执行此操作时,我遇到了问题.下面是C代码.
#include<stdio.h>
#include<string.h>
#include<unistd.h>
int main(int argc, char *argv[])
{
if ((strcmp (argv[1],"ln")) == 0 )
{
char *myargs[4];
myargs[0] = "ln";
myargs[1] = argv[3];
myargs[2] = argv[4];
myargs[3] = NULL;
execvp(myargs[0], myargs);
printf("Unreachable code\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用gcc编译这个程序后,我按如下方式运行它.
$ ./a.out ln file1 file2
ln: failed to access ‘file2’: No such file or directory
$
Run Code Online (Sandbox Code Playgroud)
这里file1存在并且file2是期望的硬链接.
任何人都可以指出我在哪里弄错了.
谢谢.
我正在尝试向堆栈推送一个值one less than %ecx.
所以我尝试了这个指令:
pushl $(%ecx - 1)
Run Code Online (Sandbox Code Playgroud)
但是我得到了以下错误as.
fact.s: Assembler messages:
fact.s:49: Error: register value used as expression
Run Code Online (Sandbox Code Playgroud)
作为一种解决方法,我做了以下事情:
movl %ecx, %edx
subl $1, %edx
pushl %edx
Run Code Online (Sandbox Code Playgroud)
但有没有办法不使用额外的寄存器(%edx在这种情况下)?并在一个指令?
对于一个简单的C程序,我gcc -E hello.c -o hello.pp看到了预处理后程序的外观.
在输出文件中,我可以看到许多行开头#,看起来像注释.这些线是什么?
如果没有这些注释,我怎么能只看到C代码?
以下是一个片段:
user $ gcc -E hello.c -o hello.pp
user $ tail -n 15 hello.pp
extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;
extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 943 "/usr/include/stdio.h" 3 4
# 3 "hello.c" 2
int main()
{
printf("Hello world \n");
return 0;
}
user $
Run Code Online (Sandbox Code Playgroud)