C Programming Language Standard - GeeksforGeeks (2024)

Last Updated : 25 Aug, 2023

Improve

Introduction:

The C programming language has several standard versions, with the most commonly used ones being C89/C90, C99, C11, and C18.

  1. C89/C90 (ANSI C or ISO C) was the first standardized version of the language, released in 1989 and 1990, respectively. This standard introduced many of the features that are still used in modern C programming, including data types, control structures, and the standard library.
  2. C99 (ISO/IEC 9899:1999) introduced several new features, including variable-length arrays, flexible array members, complex numbers, inline functions, and designated initializers. This standard also includes several new library functions and updates to existing ones.
  3. C11 (ISO/IEC 9899:2011) introduced several new features, including _Generic, static_assert, and the atomic type qualifier. This standard also includes several updates to the library, including new functions for math, threads, and memory manipulation.
  4. C18 (ISO/IEC 9899:2018) is the most recent standard and includes updates and clarifications to the language specification and the library.

When writing C code, it’s important to know which standard version is being used and to write code that is compatible with that standard. Many compilers support multiple standard versions, and it’s often possible to specify which version to use with a compiler flag or directive.

Here are some advantages and disadvantages of using the C programming language:

Advantages:

  1. Efficiency: C is a fast and efficient language that can be used to create high-performance applications.
  2. Portability: C programs can be compiled and run on a wide range of platforms and operating systems.
  3. Low-level access: C provides low-level access to system resources, making it ideal for systems programming and developing operating systems.
  4. Large user community: C has a large and active user community, which means there are many resources and libraries available for developers.
  5. Widely used: C is a widely used language, and many modern programming languages are built on top of it.

Disadvantages:

  1. Steep learning curve: C can be difficult to learn, especially for beginners, due to its complex syntax and low-level access to system resources.
  2. Lack of memory management: C does not provide automatic memory management, which can lead to memory leaks and other memory-related bugs if not handled properly.
  3. No built-in support for object-oriented programming: C does not provide built-in support for object-oriented programming, making it more difficult to write object-oriented code compared to languages like Java or Python.
  4. No built-in support for concurrency: C does not provide built-in support for concurrency, making it more difficult to write multithreaded applications compared to languages like Java or Go.
  5. Security vulnerabilities: C programs are prone to security vulnerabilities, such as buffer overflows, if not written carefully.
    Overall, C is a powerful language with many advantages, but it also requires a high degree of expertise to use effectively and has some potential drawbacks, especially for beginners or developers working on complex projects.

Importance:

important for several reasons:

  1. Choosing the right programming language: Knowing the advantages and disadvantages of C can help developers choose the right programming language for their projects. For example, if high performance is a priority, C may be a good choice, but if ease of use or built-in memory management is important, another language may be a better fit.
  2. Writing efficient code: Understanding the efficiency advantages of C can help developers write more efficient and optimized code, which is especially important for systems programming and other performance-critical applications.
  3. Avoiding common pitfalls: Understanding the potential disadvantages of C, such as memory management issues or security vulnerabilities, can help developers avoid common pitfalls and write safer, more secure code.
  4. Collaboration and communication: Knowing the advantages and disadvantages of C can also help developers communicate and collaborate effectively with others on their team or in the wider programming community.

The idea of this article is to introduce C standard.

What to do when a C program produces different results in two different compilers?
For example, consider the following simple C program.

The above program fails in GCC as the return type of main is void, but it compiles in Turbo C. How do we decide whether it is a legitimate C program or not?

Consider the following program as another example. It produces different results in different compilers.

C

// C++ Program to illustrate the difference in different

// compiler execution

#include <stdio.h>

int main()

{

int i = 1;

printf("%d %d %d\n", i++, i++, i);

return 0;

}

2 1 3 - using g++ 4.2.1 on Linux.i686
1 2 3 - using SunStudio C++ 5.9 on Linux.i686
2 1 3 - using g++ 4.2.1 on SunOS.x86pc
1 2 3 - using SunStudio C++ 5.9 on SunOS.x86pc
1 2 3 - using g++ 4.2.1 on SunOS.sun4u
1 2 3 - using SunStudio C++ 5.9 on SunOS.sun4u

Source: Stackoverflow
Which compiler is right?
The answer to all such questions is C standard. In all such cases, we need to see what C standard says about such programs.

What is C standard?
The latest C standard is ISO/IEC 9899:2018, also known as C17 as the final draft was published in 2018. Before C11, there was C99. The C11 final draft is available here. See this for a complete history of C standards.

Can we know the behavior of all programs from C standard?
C standard leaves some behavior of many C constructs as undefined and some as unspecified to simplify the specification and allow some flexibility in implementation. For example, in C the use of any automatic variable before it has been initialized yields undefined behavior and order of evaluations of subexpressions is unspecified. This specifically frees the compiler to do whatever is easiest or most efficient, should such a program be submitted.

So what is the conclusion about above two examples?
Let us consider the first example which is “void main() {}”, the standard says following about prototype of main().

The function called at program startup is named main. The implementation 
declares no prototype for this function. It shall be defined with a return
type of int and with no parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names
may be used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;10) or in some other implementation-defined manner.

So the return type void doesn’t follow the standard, and it’s something allowed by certain compilers.

Let us talk about the second example. Note the following statement in C standard is listed under unspecified behavior.

The order in which the function designator, arguments, and 
subexpressions within the arguments are evaluated in a function
call (6.5.2.2).

What to do with programs whose behavior is undefined or unspecified in standard?
As a programmer, it is never a good idea to use programming constructs whose behavior is undefined or unspecified, such programs should always be discouraged. The output of such programs may change with the compiler and/or machine.



A

Abhay Rathi

Improve

Previous Article

Features of C Programming Language

Next Article

C Hello World Program

Please Login to comment...

C Programming Language Standard - GeeksforGeeks (2024)

FAQs

Is GeeksforGeeks.org reliable? ›

Over the years, the platform has experienced exponential growth, cementing its position as one of the most trusted and renowned names in the programming community. Mission: Our mission is to empower programmers and technology enthusiasts worldwide to excel in their coding skills and unleash their full potential.

Is Geeks for Geeks course good? ›

✨Conclusion: GeeksforGeeks is an invaluable resource for anyone eager to deepen their understanding of computer science and related fields.

Why is C so much harder than Python? ›

The syntax of a C program is harder than Python. Python uses an automatic garbage collector for memory management. In C, the Programmer has to do memory management on their own. Python is a General-Purpose programming language.

Is C enough for competitive programming? ›

The answer is both. C++ is a good choice for competitive programming because it has a lot of features that make the code more efficient and stable. However, C is also a good choice because it is easier to learn than C++, and it is more widely used in competitive programming.

Is GeeksforGeeks a valid source? ›

It has a large global user base and is considered a reliable source for learning programming and computer science topics.

Is GeeksforGeeks an Indian company? ›

Intro and history: GeeksforGeeks (GFG) is a computer science portal founded by Sandeep Jain in 2009. It started as a blog to share computer science concepts and has grown into a comprehensive platform for learning and practicing coding. It is based in Noida, Uttar Pradesh, India.

Who runs GeeksforGeeks? ›

Sandeep Jain

Mr. Sandeep Jain is the founder at GeeksforGeeks. He is an alumini of Indian Institute of Technology Roorkee. His platform GeeksforGeeks is well recognized among all the engineering students throughout all colleges in India.

Is a GeeksforGeeks certificate valid? ›

For offline courses GFG does provide certification, as it has always been pre-mentioned in their courses. But no certification would be provided for Free online courses. And If there is some other type of Participation you want to ask, do tell… I would be happy to answer.

Is Geeks programming legit? ›

We applied this approach with GeeksProgramming and can confirm it's not a scam based on our experience.

How does GeeksforGeeks make money? ›

People might think that it is such a big name among programming students, Alexa ranking is great and so it might be backed by investors. But the matter of fact is that it's self-financed by Sandeep Jain, the founder and CEO of GeeksforGeeks.org. The sole source of income for GeeksforGeeks is its ads.

Top Articles
Latest Posts
Article information

Author: Gregorio Kreiger

Last Updated:

Views: 6003

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Gregorio Kreiger

Birthday: 1994-12-18

Address: 89212 Tracey Ramp, Sunside, MT 08453-0951

Phone: +9014805370218

Job: Customer Designer

Hobby: Mountain biking, Orienteering, Hiking, Sewing, Backpacking, Mushroom hunting, Backpacking

Introduction: My name is Gregorio Kreiger, I am a tender, brainy, enthusiastic, combative, agreeable, gentle, gentle person who loves writing and wants to share my knowledge and understanding with you.