Skip to content

a one liner script to compile and run simple C/C++ programs

License

Notifications You must be signed in to change notification settings

aoaaceai/c-oneliner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C oneliner

These zsh scripts compiles and runs C/C++ programs in one line.

Usage

Currently, this package includes 2 scripts, c and ppc. Both of the syntaxes are the same, so only usage for C is shown here.

Basic

This program:

#include <stdio.h>
int main() {
    printf("Hello, World!\n");
}

Can be run by using a single command:

# basic usage: compile a program and run it
c main.c
# or, for C++ programs
ppc main.cpp

Result:

Hello, World!
total   0.001
user    0.00s
sys     0.00s
mem     1 MB

Compile with arguments

# compile with parameters passed to gcc
c main.c -O2 main.c

Run with arguments

Consider this program:

#include <stdio.h>
int main(int argc, char **argv) {
    printf("The first argument is %s\n", argv[1]);
    printf("The second argument is %s\n", argv[2]);
}

The parameters can be passed to it by using:

# arguments passed to the compiled program should be after the keyword `--params`
c main.c --params FIRST second

Result:

The first argument is FIRST
The second argument is second
total   0.001
user    0.00s
sys     0.00s
mem     1 MB

Arguments before --params will be passed to the compiler, so the command

c main.c -O2 -o test --params FIRST second

will compile main.c with optimization O2, output to test, then run it with arguments FIRST and second.

Install

./configure
make install

About

a one liner script to compile and run simple C/C++ programs

Resources

License

Stars

Watchers

Forks

Packages

No packages published