Thread: Beginner question.. wich compiler

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    11

    Beginner question.. wich compiler

    Hi..
    I just started out with C and beginning to like it .. With the help of "The C Programming Language" by Kernighan and Rithie I certainly have the feeling it will all work out..

    Question though... what is a good compiler/editor to use ..
    Right now I have NANO & GCC on my linux box (which is fine .. don't really code much there)

    On my windows box I'm currently using Pelles C. I also tried Visual Studio Express but it's so big :P ... I feel like I'm trying to eat soup with a shovel instead of a spoon with visual studio .. Is it worth while trying to work things out in visual studio or is it best to stay with a plain simple compiler like pelles?

    also is it ok to use C++ compiler for C coding ?? I know it works in most cases.. But since I'm learning C from scratch I don't want to end up knowing C but having C++ habits because of the compiler. most compilers I've tried do not have a C option only C++ ..

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    All 3 of them are good.
    GCC GNU Compiler collection has many compilers C,C++,Objective-C,etc.

    gcc is gnu C compiler. C99 support. probably one of the best.
    Pelles is only C. Supports C99. Not sure to what extent...
    VS does not support C99.

    If you're going to learn C++ later on, I'd choose either gcc or VS. since you'll already get familiar with its environment.

    >>most compilers I've tried do not have a C option only C++
    ???

    Use C compiler to compile C code.
    Last edited by Bayint Naung; 03-27-2011 at 07:24 AM.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I would recommend against using VS for C programming as well, for both reasons pointed out above:

    1) It's too big
    2) It doesn't support the standard

    You can use Pelles or Codeblocks with GCC (MinGW on Windows).

    On the C/C++ compiler issue you can use GCC (GNU C Compiler) to compile C code and g++(GNU C++) compiler to compile c++ code.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    11
    OK... The plan is to go to C++ & Assambly in time .. but first C :P ...

    Well the problem in VS is when I start a new project I only have the options : Visual C++, Visual Basic, Visual C# or visual F#. No explicit C option.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    I think it's worth spending the time making friends with Visual Studio. Compiler-wise, I don't know anything of Pelles C. I recommend VS primarily because of the debugger -- as already said the compiler doesn't support C99...

    The debugger is invaluable though. It will save you hours!! Plus if you edit, build, run, debug all in visual studio it doesn't feel quite so painfully bulky.

    VS has a "C and C++ compiler". The easiest thing to do is use .c file extension for C files and cpp for C++ -- the compiler will automatically do the right thing for the extension.
    From the GUI you can set it on a per-file basis by right clicking the source file, properties->C/C++->Advanced->Compile As.

    Quote Originally Posted by viper2k View Post
    OK... The plan is to go to C++ & Assambly in time .. but first C :P ...

    Well the problem in VS is when I start a new project I only have the options : Visual C++, Visual Basic, Visual C# or visual F#. No explicit C option.
    You will want Visual C++ -- Win32 Console Application at this point. I recommend selecting "empty project" in "application settings" after you click next after selecting project type. This avoids complications with precompiled headers.

    Then you can create new or add existing files in the "solution explorer". .c for C, .cpp for C++. Or if you want to compile from the command line, C is /TC C++ is /TP
    Last edited by smokeyangel; 03-27-2011 at 07:41 AM.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by viper2k View Post
    On my windows box I'm currently using Pelles C. I also tried Visual Studio Express but it's so big :P ... I feel like I'm trying to eat soup with a shovel instead of a spoon with visual studio .. Is it worth while trying to work things out in visual studio or is it best to stay with a plain simple compiler like pelles?

    also is it ok to use C++ compiler for C coding ?? I know it works in most cases.. But since I'm learning C from scratch I don't want to end up knowing C but having C++ habits because of the compiler. most compilers I've tried do not have a C option only C++ ..
    If you're only interested in C coding on Windows, I think you'll find the Pelles C IDE/Compiler is the right tool. It is C-99 compliant and the help file makes note of anything in the library that isn't. It also produces free-standing EXE files that do not depend on external run time libraries. Don't let it's smaller size fool you, it's a very capable setup... I use it routinely in Windows GUI development as well as CLI (Console) projects and it's never let me down yet.

    Visual Studio, like everything Microsoft is a bloated monstrosity that tries to do way too much. The C/C++ compiler that comes with it (also included with the SDK) is a pretty good compiler but it's not C standards compliant.

    Additionally I would suggest you consider what you don't get with most IDEs... For example, Code::Blocks has no resource editing features at all. If you are doing Windows GUI work, you will have to come up with free standing editors for things like dialogs, string tables, accellerators, etc. where Pelle has these built right into his IDE.

    You can indeed use a C++ compiler for C coding... but only at the expense of standards... To get C and C++ from the same compiler requires some compromise. For example the MS compiler that comes with the SDK or VS is not C-99 compliant and there are several features of that standard it will puke on. So if there's a chance your code might need to be built on different compilers, you will almost certainly run into compatibiliby issues.

    I started out on Pascal way back when. Then when Borland killed it, I was left with a scramble to find a decent programming setup for my little jobs. I've probably looked at a dozen or so languages and a lot more compilers. Even now I periodically try different things... but somehow I always seem to end up back on Pelles C.

    (Yeah, I know this sounds like an advertisement, but it's the truth. I have no connection to Pelles C other than it being probably the best setup you can get for free.)

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    11
    lol ok .. I think I'll stick with Pelles and GCC for now then..

    My main goal at this moment is to learn C the right way and if I see the replies my humble conclusion is that with VS and so I am bound to learn come C++ habits in coding C ..

    As said before I want to extend to C++ and Assambly later on .. but made the choice to go for C first.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by viper2k View Post
    lol ok .. I think I'll stick with Pelles and GCC for now then..

    My main goal at this moment is to learn C the right way and if I see the replies my humble conclusion is that with VS and so I am bound to learn come C++ habits in coding C ..

    As said before I want to extend to C++ and Assambly later on .. but made the choice to go for C first.
    I did much the same thing. Ventured into C++ only a couple of months ago after 6 years of C coding. But then, I guess I had a problem most people don't... C++ just didn't make any sense to me so I was blocked, until the gang here went to bat and helped me understand. (Most here are pretty good people, btw.)

    I've recently seen several examples here where people aren't seeing the difference between languages --one case where a teacher is even *teaching* some hodgepodge of C dialects-- and I shudder to think what kind of problems people will run into because of it. So you are very smart to start with one language then move to the next only when you're confident in the first...

    One step I would suggest as an intermediate, because you'll lose touch with it when you start using higher level languages, is to learn some Windows API programming while still on C... It is very different than CLI coding and provides a very interesting challenge. If you can take at least the fundimentals to C++ or whereever you land, I'm very sure you'll be a better programmer for it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner C Question Help
    By pmacdonald in forum C Programming
    Replies: 32
    Last Post: 06-22-2011, 09:32 PM
  2. Beginner Question about Pointers in C
    By lucidrave in forum C Programming
    Replies: 2
    Last Post: 08-01-2009, 03:15 PM
  3. question about a compiler warning
    By sashaKap in forum C Programming
    Replies: 4
    Last Post: 03-17-2009, 09:47 AM
  4. New to C, small compiler question
    By Ash1981 in forum C Programming
    Replies: 14
    Last Post: 12-31-2005, 02:16 AM
  5. gcc compiler question
    By s_ny33 in forum C Programming
    Replies: 6
    Last Post: 10-18-2005, 07:13 AM