然而,为了加快创建C程序所需的时间,可以自动化许多事情。我想用类似Python但具有C语义的东西来编写我的程序。这意味着,所有关键字都是C关键字,但语法被优化了。
例如,这段C代码:
#include "dsplib.h"
#include "coeffs.h"
#define MODULENAME "dsplib"
#define NUM_SAMPLES 320
typedef float t_Vec;
typedef struct s_Inter
{
char *pc_Name;
struct s_Inter *px_Next;
}t_Inter;
typedef struct s_DspLibControl
{
t_Vec f_Y;
}t_DspLibControl;
void v_DspLibName(void)
{
printf("Module: %s", MODULENAME); printf("\n");
}
int v_DspLibInitInterControl(t_DspLibControl *px_Con)
{
int y;
px_Con->f_Y = 0.0;
for(int i=0;i<10;i++)
{
y += i * i;
}
return y;
}
在优化的 Python 版本中,可以看起来像这样:
include dsplib, coeffs
define MODULENAME="dsplib", NUM_SAMPLES=320
typedef float t_Vec
typedef struct s_Inter:
char *pc_Name
struct s_Inter *px_Next
t_Inter
typedef struct s_DspLibControl:
t_Vec f_Y
t_DspLibControl
v_DspLibName():
printf("Module: %s", MODULENAME); printf("\n")
int v_DspLibInitInterControl(t_DspLibControl *px_Con):
int y
px_Con->f_Y = 0.0
for int i=0;i<10;i++:
y += i * i
return y
我的问题是:你知道有没有任何VIM脚本可以将原始的Python化的C代码转换成标准的C代码吗?例如,一个人正在编写C代码,但使用了Python化的语法。一旦她决定将Python化的块转换为标准的C代码,她选择这些块并按下某个键。当然,她不会保存这种Python化的代码,VIM会将其转换为标准的C代码。
#define BEGIN {
和#define END }
的头文件。 - caf