Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C/++/# Can I use Microsoft Visual Studio For coding C ?

  1. Oct 13, 2018 at 12:56 PM #1
    I will take Intro to C programming this semester and can I use MVS for coding C ?
     
  2. jcsd
  3. Oct 13, 2018 at 1:14 PM #2

    Mark44

    Staff: Mentor

    Yes. I use it for both C and C++ programs.

    A C program should have a name with a file extension of .c. The extension for C++ programs is .cpp. There are also some switches in the property pages for your code to specify which language, but the easiest way is to use the file extensions I listed.
     
  4. Oct 13, 2018 at 2:01 PM #3
    Is it possible that it can harm my computer If I do smthing wrong in the downloading process ? How can I download and run it safely ?
     
  5. Oct 13, 2018 at 2:04 PM #4

    Mark44

    Staff: Mentor

    I haven't heard of anyone having something go wrong when they downloaded Vis. Studio.
     
  6. Oct 13, 2018 at 2:10 PM #5
    İnstructor shared a link for to run C in MinGW. But I couldnt download it from there cause its too complex .
    http://mingw.org/wiki/Getting_Started
    "After installation you will need to perform some additional tasks yourself to ensure your MinGW applications will run. Most importantly, you will need to make changes to your PATH environment variable. Be careful: there are two PATH variables which can be changed, and changing the wrong one can have significant consequences. Instructions for changing the correct PATH variable are provided below."

    And many more warnings etc. I guess theres no such needs in MVS
     
  7. Oct 13, 2018 at 3:09 PM #6

    jim mcnamara

    User Avatar

    Staff: Mentor

    Simply download cygwin. It is a windows app. It acts like linux. Free. https://www.cygwin.com/

    If you cannot do that and you are on Windows 10, then you can get an Ubuntu Linux app. Free. Install WSL from Microsoft.

    In either case you need to understand that Windows text files have a line ending (carriage control) of ASCII 10, and ASCII 13. Two characters usually noted by "\n" and "\r". (\r shows in UNIX editors as "^M" which is a red flag.)

    Ubuntu and cygwin use ONLY "\n". In Linux speak, this is called a UNIX file, the other one, "\n\r", is called a windows file. Most editors will change a text file to either one. If you use a windows editor, then compile it in Linux you will get a bunch of errors because of the wrong line ending. So fix the type of file first. Then, no errors.
     
  8. Oct 13, 2018 at 3:25 PM #7

    verty

    User Avatar
    Homework Helper

    If you do use GCC, consider using the editor SciTE. If you turn on line numbering it'll make debugging very easy because GCC has very good error messages when you use -Wall -Wextra -pedantic. I suppose the one challenge with GCC is you need to learn how to write a Makefile but that is not hard to do and once you have the file, you can always reuse it. (A Makefile is like the solution in Visual Studio. It references all the files of your project and compiles it in the correct order to produce the executable.)
     
  9. Oct 13, 2018 at 3:36 PM #8
    I need some good explaining videos for these possible C IDE s.
     
  10. Oct 13, 2018 at 4:21 PM #9

    QuantumQuest

    User Avatar
    Science Advisor
    Gold Member

    I agree with @Mark44 that you can download and use it with no problems. It is a good super-IDE but just try to stay focused on your code and learn the extra IDE features with patience. Many years before I was using DevC++ and it was good enough for educational purposes as well as for building some open source software.- more recently I had installed a fork with C++11 support. There is a relatively new release at SourceForge.net .

    I always liked to tinker with tool chains particularly of GCC, as a way to learn and set up things exactly the way I like. The same holds for maintaining and modifying if necessary the PATHs of Windows, as for a lot of other Windows OS things. But these don't come as suggestions without warnings. If you really like to do it this way - even independently of Microsoft Visual Studio, you have to study through resources, references and tutorials and do things in a safe way without putting anything at stake. If you're aiming to be a good programmer or software developer, I would also recommend to learn to program on a Linux distro besides Windows.
     
  11. Oct 13, 2018 at 5:06 PM #10
    I did a bit research and find that Code Block is best for beginners. I downloaded it and I can manage to use it

    I downloaded the MVS and tried to use it but some problems came up which I dont remember now. But maybe I download it later. But for now I think Code Block is nice and have much simpler user interface for me.
     
  12. Oct 13, 2018 at 5:20 PM #11

    verty

    User Avatar
    Homework Helper

    I installed VC++ because I wanted to see how easy it was to set up but I can't get it to work right either. For example, I tried to #include <stdio.h>; and it complains, but #include <cstdio>; doesn't.

    @Mark44, can you elaborate on what settings need to change to enable C in the most compatible way possible? Thanks.
     
  13. Oct 13, 2018 at 6:09 PM #12

    QuantumQuest

    User Avatar
    Science Advisor
    Gold Member

    Assuming that you have installed the Visual C++ redistributable for Visual Studio 2017, you can create "New Project" > "Visual C++" > "Win32 Console Application" >"Next" > "Console Application" and "Empty Project". Now, click "Finish" and add a new source file from the relevant menu and give your source file name the .c extension, ignoring the options displayed. Hope this helps.

    As for <cstdio>, it includes <stdio.h> and adds the associated names to the std namespace. Here's the relevant Microsoft web page.
     
  14. Oct 13, 2018 at 6:51 PM #13

    verty

    User Avatar
    Homework Helper

    Thanks. It was my fault in the end, I deselected a bunch of stuff in the installer, too many in fact, but adding them back left the solution in a confused state. I had to delete it and create a new solution and it's now working properly. I think I prefer Code::Blocks (I tried that after Arman mentioned it) because it's closer to how it is on Linux. The one difference I see is it uses g++ to link the executable like so: g++ -o myapp.exe main.o. But otherwise it's just like it is on Linux which should be very compatible with his class although from what I can tell, adding main.c to an empty project in MSVC is working fine as well.

    @Mark44, there's no need to reply because I've got it working. It was my own fault in the end for trying to make the install smaller.
     
  15. Oct 13, 2018 at 6:56 PM #14

    Mark44

    Staff: Mentor

    Once you have loaded your project in VS, open Solution Explorer, if you don't already have that as a pane that is showing. To open the Solution Explorer pane, under View, click Solution Explorer.

    Select the source code file in your project (I'm assuming you have only one source code file). From the right-click menu for that file, choose Properties, the last selection in this list. This opens a dialog box labelled <File name> Property Pages.

    In the left pane at the top level it says Configuration Properties. Under that there are two headings: General and C/C++. Expand the C/C++ heading. Two up from the bottom is Advanced. One option there is Compile As, which normally has Default as the option. Change this option to Compile as C Code, if that's how you want your code to be compiled. After that, click OK if you're done, or Apply if you want to change some other settings and aren't ready to close the Property Pages.

    As I understand things, the usual setting of Default causes source files whose extension is .c to be compiled as C code, and files with a .cpp extension are compiled as C++ code. If you manually change the Compile As setting as described above, you can choose which back end does the compilation regardless of the file extension you have used -- I believe.
     
  16. Oct 13, 2018 at 8:06 PM #15

    phinds

    User Avatar
    Gold Member

    Just FYI, C coding is what MVS started with and it has never been left out. As for installations, I've installed many versions on several different machines and have never had the least bit of problem. It's really wonderful that MS now gives away the full version to individuals. I've paid out quite a bit for versions over the years (I've been using it from the beginning) and I was delighted when I found that it's now free.
     
  17. Oct 14, 2018 at 1:13 AM #16

    rcgldr

    User Avatar
    Homework Helper

    I use Visual Studio desktop express 2015, which is the last version before Microsoft switched to the community version. You can start here to download an "older" version:

    https://visualstudio.microsoft.com/vs/older-downloads

    Either way, you'll need to create a Microsoft account. If you're running Windows XP or XP X64, then the latest version of VS that will run on XP is Visual Studio C/C++ express 2010 (instead of desktop express). VS2010 is available as an ISO file. I don't think you need a Microsoft account to use VS2010.

    Note that Microsoft's C compilers are essentially C89 compliant, not C99 or later. I'm not sure of the differences. Some C compilers allow variable length arrays (VLA), but even C++ standards don't support VLA, so I would avoid it. If you want a stack based array, you can use _alloca() with VS (it may be called alloca() for other compilers), but be aware if that if a stack based array is too large, you can get a stack overflow error.
     
  18. Oct 14, 2018 at 1:50 PM #17

    verty

    User Avatar
    Homework Helper

    Thinking of C again reminds me of when I learned to program using Turbo C++. The help pages were very good and I've liked C languages ever since. I particularly like how everything is pretty easy to do if you know what function to call. Functions like memset, memcopy, etc, don't seem to exist in other languages. And I like how pointers work like arrays. And you can pass by reference by using the address-of operator (&). And of course it has the switch statement that has made it into almost every language but not Python for some reason. So I do like C and this was a nice reminder, seeing if MSVC could work in a compatible way. So thanks.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted