Speedup writing C programs using a subset of the Python syntax
Posted
by psihodelia
on Stack Overflow
See other posts from Stack Overflow
or by psihodelia
Published on 2009-12-16T10:48:52Z
Indexed on
2010/03/27
15:43 UTC
Read the original article
Hit count: 320
I am constantly trying to optimize my time. Writing a C code takes a lot of time and requires much more keyboard touches than say writing a Python program.
However, in order to speed up the time required to create a C program, one can automatize many things. I'd like to write my programs using smth. like Python but with C semantics. It means, all keywords are C keywords, but syntax is optimized.
For example, this C code:
#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;
}
in optimized pythonized version can look like:
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
My question is: Do you know any VIM script, which allows to translate an original pythonized C code into a standard C code? For example, one is writing a C code but uses pythonized syntax, once she decides to translate pythonized blocks into standard C, she selects such blocks and press some key. And she doesn't save such pythonized code of course, VIM translates it into standard C.
© Stack Overflow or respective owner