Posts

Showing posts with the label C

How to create a "c python"?

In python, all python code are translated into c action in real time. Line by line. If python can do it, c can do it too. In other words, you can create a c_interpreter to translate c code into real time c actions. So that you can create variable in real time, do math operations in real time. import another c file in real time. A example would be: ``` int i = 999; i = i + 1; ``` becomes ``` int *i = (int *)malloc(sizeof(int)); *i = 999; *i = *i + 1; ``` By doing so, you can have a python_like c interpreter, you can run your c code without using gcc again. You can bypass the glibc version restrictions. You can have a python_like interpreter that could handle memory pointer stuff, and speed is just as quick as c. > Sometimes, I think the python is a remote controller, you give it code, it run it line by line to control your computer. Now c could do the same thing.

Linux USB midi driver in c or python

C: ``` // Linux MIDI input driver, protocol 1.0, there is no need to upgrade to protocol 2.0 // Author: yingshaoxo // Run it in root shell // gcc main.c -o main.run // ./main.run #include <sys/soundcard.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #define  MIDI_DEVICE  "/dev/midi1" //#define  MIDI_DEVICE  "/dev/dmmidi1" //#define  MIDI_DEVICE  "/dev/snd/midiC1D0" int main(void) {     unsigned char inpacket[4];     // first open the sequencer device for reading.     int seqfd = open(MIDI_DEVICE, O_RDONLY);     if (seqfd == -1) {         printf("Error: cannot open %s\n", MIDI_DEVICE);         exit(1);     }     // now just wait around for MIDI bytes to arrive and print them to screen.     while (1) {         read(seqfd, &inpacket, sizeof(inpacket));    ...

How to let YouCompleteMe handle c99 project?

Create a .ycm_extra_conf.py file  vim ~/.vim/.ycm_extra_conf.py def Settings( **kwargs ): return { 'flags': [ '-std=gnu99', #'-std=c99', '-x', 'c', #'-std=cpp11', #'-x', 'c++', '-static', '-no-pie', #'-D_POSIX_SOURCE', ], } Add one line in ~/.vimrc vim ~/.vimrc let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py' ​