PythontoBeLoved
PythontoBeLoved

Reputation: 723

How do you try out small/simple C or C++ source codes?

It is very easy on Linux to fire-up vi and write a 100-200 lines of code, compile and see the results: ie. Trying small simple examples of C/C++ code.

On windows however, I like Visual Studio but to use it you have create a new solution then a project which then creates a new folder, generates very large PDB and caching files and a small example of 100-200 LOC becomes a 20Mb large project(?!) after compilation.

So the question is how do you write this kind of small codes on Windows? Possibly Cygwin or Dev-C++ (which is not active since 2004?).

Upvotes: 8

Views: 1496

Answers (18)

kuszi
kuszi

Reputation: 2079

For small/simple C or C++ source codes I use Ideone. It supports over 40 programming languages.

Upvotes: 1

Matt Stephenson
Matt Stephenson

Reputation: 8620

I use cl.exe and nmake.exe from Visual C++ Express to compile small groups of .c and .cpp files. Rolling your own simple Makefile for nmake.exe is easy.

Upvotes: 0

anon
anon

Reputation:

For small bits of code I want to test, such as code that I'm going to include in an SO answer, I always use the command line. My tools on Windows are:

  • the MSYS tools, particularly their bash shell
  • the vim editor
  • the MinGW GCC compiler (Twilight Dragon branch)

Upvotes: 2

Stack Overflow is garbage
Stack Overflow is garbage

Reputation: 248159

I've got a Visual Studio test project with a main file I just overwrite every time I want to test something new. The couple of MB taken up by the .ncb file really really really doesn't matter. A bigger issues is the need to create a project. But I get around that by reusing an old test project.

Upvotes: 1

Pod
Pod

Reputation: 4129

You can do the exact same thing for Windows -- fire up VI and run the output through gcc.

Either get MingGW/MSys, Cygwin, or native ports of each app (gnu tools, vi)

Just because you're using Windows, doesn't mean you're forced to use Visual Studio.

Upvotes: 1

KitsuneYMG
KitsuneYMG

Reputation: 12901

Maybe I'm just a *nix geek, but I went on over to http://consoletelnet.sourceforge.net/gccwin32.html and got gcc for win32. I then headed over to http://unxutils.sourceforge.net/ and go these command line tools. (I renamed their find.exe to gfind.exe to avoid conflict with windows find). I then use gvim for win32 to write code and make/gcc to compile it. Now I only have to learn one environment.

Upvotes: 2

beermann
beermann

Reputation: 358

And if you don't have access to your local computer, or you are to lazy to look for command line compiler you can paste your code to on-line compiler. There are several of them on the net you can try one of them here. It's free, no registration needed. It has some flaws but for quick code check it's just fine.

You can also use some other languages, C, C++, D, Haskell, Lua, OCaml, PHP, Perl, Python, Ruby, Scheme, Tcl to be precise.

Upvotes: 2

pmg
pmg

Reputation: 108978

When you installed Visual Studio it created an entry in your programs named something like "Visual Studio Command Prompt" (maybe in a group "Visual Studio Tools").

Execute that Command Prompt (it sets up some environment variables needed for the command line compiler) and use cl, the command line compiler.

> cl /?
Copyright (C) Microsoft Corporation.  All rights reserved.

                         C/C++ COMPILER OPTIONS


                              -OPTIMIZATION-

/O1 minimize space                      /O2 maximize speed
/Ob<n> inline expansion (default n=0)   /Od disable optimizations (default)
/Og enable global optimization          /Oi[-] enable intrinsic functions
...

Edit -- copy from another answer :)

Microsoft Documentation: VS2005, VS2008

Upvotes: 7

sbi
sbi

Reputation: 224139

I have a Test.sln which has a Test.vcproj which has a Test.cpp. The solution has a few handy configurations (for maximum C++ std conformance and others). I just paste code into/from the Test.cpp file and compile it that way.

Upvotes: 0

Travis
Travis

Reputation: 544

MinGW is a good solution if you're not using anything Visual Studio specific. If you are, in the start menu with Visual Studio, there should be a script that starts a "commandline" for visual studio.

Also, please keep in mind, even if you aren't going to use Visual Studio, if you use MinGW, you're going to run into issues even with things you might not expect (like...if you decide to try the Apple Bonjour SDK, in which case you're going to get nasty link errors) because GCC and MSVC++ libraries don't always play nice.

Upvotes: 3

me_and
me_and

Reputation: 15664

I also use Visual Studio; for quick testing and prototyping, I have a file scratch.c on my desktop, which I just load up and test things out in.

I don't see opening Visual Studio, clicking the new document icon, writing code, pressing F5 then just accepting the defaults for everything as being too much effort :)

The other alternative I have (which I don't use for C, but do for Haskell) is to PuTTY into a Linux box I have access to, and do everything on there.

Upvotes: 0

Terje Mikal
Terje Mikal

Reputation: 947

I always use MinGW (GCC for windows) for such tasks.

Upvotes: 3

Alok Singhal
Alok Singhal

Reputation: 96191

I haven't used any of them, but MinGW and lcc-win32 seem to be pretty lightweight, and people seem to like them in news:comp.lang.c. MinGW is a port of GNU Compiler Collection for Windows and is free, lcc-win32 is free for non-commercial use.

Upvotes: 1

Luke Narramore
Luke Narramore

Reputation: 509

I have used Dev-C++ post 2004, and it still works quite well.

I even used projects coded in Dev-C++ for my practicals that had to run on machines using Linux. Just changed the make files.

Upvotes: 0

OregonGhost
OregonGhost

Reputation: 23759

I think there's nothing wrong with firing up Visual Studio for some testing. You can delete the 20MB afterwards ;)

However, you can also just invoke the command line compiler on Windows. Just start a Windows SDK console (or Visual Studio console) and you're there. And you can even use vi (need to install it first, of course).

Upvotes: 5

Pascal Cuoq
Pascal Cuoq

Reputation: 80325

For the simplest examples codepad may be an option.

Upvotes: 6

Tryum
Tryum

Reputation: 660

I usually edit my code within notepad++ then compile it with gcc under cygwin or msys.

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 994011

You can compile from the command line using cl.exe. See the MSDN article How to: Compile a Native C++ Program from the Command Line for detailed instructions.

Upvotes: 13

Related Questions