4

Okies, totally newbie question here. I can read the code, mimic the code and understand the basics to be deadly. But, I never really took the time to understand what ANSI C really meant. I just look and code. Been doing it since I was 15 years old and I'm 33 now.

It's been awhile since I touched C, but getting back into the swing of things with some code on my Linux box made things difficult. My code is old, everything else is new from the Linux distro to GCC. When I go to compile, everything works, but now I have slew of new warnings that I can only assume tie to a new standard?

 gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4

How can I tackle this problem? I never quite understood the difference between C89 and C11. How can I tell what I'm using?

Any help is much appreciated. I want to try to resolve these warnings while also trying to learn what I clearly failed to grasp.

  • 1
    Are you asking how to tell the compiler what version of the standard to use or how to tell what version the code you've written complies with? Also, the warning message itself should tell you what's (looking) wrong. If you don't understand what a particular warning means, please post minimal but self-contained code to trigger it and the exact text of the warning message itself. – 5gon12eder Mar 26 '16 at 3:52
5

In the case of gcc, you can tell the compiler what C standard to use via the --std option. Running man gcc will explain this, and will list all of the standards that are supported. Note that there are lots of variations including some "standards" that are GCC specific extensions / variations to the official standards.

If you want to understand why certain things in your code are giving you warnings, you would need to trace back to the particular standard that the warning message is referring to, and READ the relevant part of the standard.


But, I never really took the time to understand what ANSI C really meant.

You need to remedy that. Your poor understanding is most likely the root of a lots of mysterious bugs that arise when you change compilers, port code from one platform to another, etcetera. (The kind of thing that lots of people incorrectly blame on "compiler bugs".)

  • I ended up finding the --std option and applying it to the Makefile. I saw that my version of GCC is default --std=gcc11 or whatever. – Fastidious Mar 26 '16 at 15:00
4

If you were not consciously trying to follow the ANSI standard when writing the code, then most likely your code will not conform to any of the ANSI C standards.
The reason for this is because there are no C compilers that by default enforce an ANSI C standard, but they all accept their own dialect of C.

To add to that, if your program tries to do user-interaction in a more fanciful manner than "print a prompt and read a line of text", then you must already step beyond the facilities provided by ANSI C. If you are unaware of that, then it is easy to pick a solution that is specific for the compiler you are using at that time.


If you want to start following ANSI C strictly, then you must accept that your programs can't do fancy user interaction and can't support most other kinds of connections to the outside world.

If you don't actually care that much about standard conformance, but you want your program to be portable between different platforms and compilers, then you should learn about ANSI C to know what it provides and then deliberately choose portable (3rd-party) libraries for the features that you need beyond what the satndard offers you.

  • Just for context. The program is a online game. So, fancing user interactions and connection to the outside world is a must. Does that mean I should steer away from ANSI C? That could be why it's not like it. – Fastidious Mar 26 '16 at 14:58
  • 1
    @Fastidious: The game logic can probably be done in ANSI C, but for the network connections you will need to use facilities that are not available in ANSI C. – Bart van Ingen Schenau Mar 26 '16 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.