How to quickly check a piece of C or C ++ code?

I use Ubuntu and Eclipse as an IDE for C / C ++.

I am currently having a large project in Eclipse. Sometimes I want to test some small functions written in C / C ++, but I don't want to recreate a new project in Eclipse. It takes a lot of time and slower. I want to ask if there is a better way to do this?

(I used to use a combination of GEDIT and GCC from the shell, but I really like the Eclipse autocompletion or intellisense function that GEDIT does not have. I also tried Scribes, but it doesnโ€™t have a full intellisense function like Eclipse)

+6
source share
5 answers

Use an online compiler like Ideone or Codepad .
Of course, they donโ€™t provide automatic code completion and other fancy features, but this is the price you pay for a quick and easy way to test standalone functions.

+7
source

This method works without an internet connection and does not expose you to code.

<ctrl>+<alt>+T <-- 0) opens a terminal vi test.cc <-- 1) hackery ... g++ -Wall -Wextra test.cc && ./a.out <-- 2) compile + run rm test.cc <-- 3) clean up (optional) 

Replace vi favorite editor or cat . It can not be less intrusive.

Some editors, such as SciTE , have very simple base code (btw btw: SciTE has shortcuts to directly compile and run code from within the editor).

Btw: QtCreator gives a decent "intellisense", and the project files are minimal. For such a single-function test, one line of the project file is enough.


unkulunkulu indicates that you can also replace step 2 as follows ( itโ€™s better not to have a Makefile in your test folder, it may contradict your existing goals in ):

 <ctrl>+<alt>+T <-- 0) opens a terminal vi test.cc <-- 1) hackery ... make test && test <-- 2) compile + run rm test.cc <-- 3) clean up (optional) 

It has a tiny flaw in that the g ++ message about additional arguments (e.g. -Wall or -std=c++0x is a bit more intrusive).

+5
source

I will advise you to use gedit with a connected terminal plugin. It allows you to quickly compile through the built-in terminal. Effect for quick testing.

+1
source

You can use tcc as a C script engine.

 $ cat tcctest.c 
  #! / usr / bin / tcc -run
 #include <stdio.h>
 int main (void) {
     printf ("Hello, tcc! \ n");
     return 0;
 }
 $ chmod u+x tcctest.c $ ./tcctest.c 
  Hello tcc!
+1
source

http://www.compileonline.com I found this site is more useful than ideon or codeword, because it supports more languages โ€‹โ€‹than codeword, and you can see the output of your code in an adjacent window, you can also provide standard inputs and command line arguments, and you can also access the input.txt file in your program.

CompileOnlineScreenShot

0
source

Source: https://habr.com/ru/post/893491/


All Articles