Need to write GCC compatible C

Leros

Lifer
Jul 11, 2004
21,867
7
81
I need to write C code which will compile on GCC on a Unix environment at school. I have SSH access to these machines, but I would like to work locally on my Windows box.

I looked at various IDEs and none of them look any good. The only one I like is Visual Studio, but it does not use GCC.

Question: If I program my C code on Visual Studio, am I going to be able to compile the same code on GCC?


I've used Eclipse C++ (which use MinGW GCC), but it behaves very strangely.
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
You can install gcc locally (e.g., using Cygwin) and develop with that. However, as long as you aren't doing anything particularly fancy, your code will likely be portable between Visual Studio and gcc (but there are of course no guarantees). You could try using flags to ensure Visual Studio and gcc are both compiling to the same standard (e.g., C89 or C99), but still that assumes they both implement the standards identically, which they probably don't (though again, the differences likely won't affect you).
 
Oct 27, 2007
17,009
5
0
Don't use any MS extensions and you're golden, mostly. In my C class we had to write C89 compatible code for everything we did, but I never really found it getting in my way. I developed in Visual Studio for about half of my work.
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
There are SOME differences in the microsoft C++ compiler and the gcc compiler. Most of them are fairly minor and easy to correct. The main thing is that you don't use headers specific to MS or unix, and you should be fine.

(An example of differences vector<vector<string>> blah; is valid in the ms compiler, however it throws errors in gcc because of the >>. So with GCC the line would have to be vector< vector<string> > blah; which will compile on both compilers. Though, I don't believe C really has that problem.)
 

hans007

Lifer
Feb 1, 2000
20,212
18
81
just code win32 console apps as your projects and dont add any of the windows libs or headers and it will work fine.

I did the same thing when i was in school (visual studio 6 at the time).

you could also just get eclipse with the c++ plugins. CDT or something.
 

Net

Golden Member
Aug 30, 2003
1,592
3
81
strangely in what way?

as hans007 mentioned. you can use eclipse c++. install cygwin. when you start your project right click on the project - > properties -> c++ somthing somthing -> patterns and symbols. under that you select the includes of gcc or g++

i did it. worked okay. gdb debugger worked on somethings but not all that well.... i installed linux and i haven't any reason to go back to windows. note: haven't had any slow down since the first day of my linux install, something you can't say about windows.

if you have a fast internet connection you can use putty and Xforwarding for your gui.

virtual machine if your computer is fast.

you shouldn't have any problem using visual studio.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Not all Linux (I assume gcc implies Linux in this case) features will be available on a windows platform, of course. Depending on your project, you might be OK, might not. As others have said, stick entirely to the C standard, limit use of libraries, and you might squeeze by.

The better option by far is to just bite the bullet and learn how to use linux over putty to code, especially if you are planning on taking more classes on Linux.