Running C on different compilers

This is a discussion on Running C on different compilers within the C Programming forums, part of the General Programming Boards category; Hi all I find when I run the same C program on these two different compilers I get different results. ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    57

    Running C on different compilers

    Hi all

    I find when I run the same C program on these two different compilers I get different results.

    Visual Studio C++ 6.0 (1999)

    gcc on Mandrake linux (2000)

    How serious is this problem? I assumed because C++ is a superset of C, that the visual studio compiler would be satisfactory and C programs would run the same on both. So far this is definately not the case

  2. #2
    Registered User
    Join Date
    May 2005
    Posts
    22
    C++ is a superset of C, but there are many changes, such as scoping. One of the more experienced coders here could probably tell you the differences in great detail.

    Instead, see if it works with g++. I'm not a compiler expert, so I don't know how many differences there are between the VC++ and g++ compilers.
    Last edited by shuuhen; 09-13-2006 at 05:43 PM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > I find when I run the same C program on these two different compilers I get different results.
    Post an example, and the different results.

    If your code is correct, then you should be getting the same results on both machines consistently. I certainly do (and with many different compilers).


    http://david.tribble.com/text/cdiffs.htm
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    57
    Perhaps it is like different browsers? Internet Explorer and Firefox tend to catch different errors, and they tend to go easy on different errors, so the same page may not work on both or might appear differently on both, depending on any subtle errors one makes.

    So if you write bulletproof C code it should work okay on all compilers? Is anyone else sure about this.

    I know writing compilers is tricky. I'm sure it's possible different compilers might see the same code differently, especially between C and C++ compilers?

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Make sure you're not compiling as C++ on your C++ compiler.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I find when I run the same C program on these two different compilers I get different results.
    If the program actually compiles on both compilers, it typically means you've got a bug in your code. Or it could be the code is nonportable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 10-18-2004, 10:14 AM
  2. amd 2600+ (333) running at 266mhz
    By Kinasz in forum Tech Board
    Replies: 8
    Last Post: 05-14-2004, 04:11 PM
  3. running programs as "hidden" or in the "background"
    By Leeman_s in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 03:47 AM
  4. Other GOOD FREE compilers
    By DarkViper in forum C++ Programming
    Replies: 8
    Last Post: 12-07-2002, 09:16 PM
  5. RE: Find out running processes from command prompt
    By sampatel in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-18-2001, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21