Undefined Behavior
Undefined Behavior

Reputation: 2208

What is the behavior when a new C programming language standard is official, the old standard is ALWAYS compatible?

Are there any deprecation between c89/90 c99 c11 c18? Or only recommendation of avoid certain function like strlen and use a "safer" strnlen_s?

Upvotes: 0

Views: 207

Answers (2)

Lundin
Lundin

Reputation: 213306

Newer standards are not guaranteed to be compatible, even though the committee has a (far too) strong focus on backwards compatibility.

  • C90 is not completely compatible with newer versions.
  • C11 and C17 are compatible with C99, apart from some corrections.

Official recommendations of functions to avoid are found in:

  • C17 6.11 Future language directions, and
  • C17 6.32 Future library directions

Notably, the official recommendations are free from misguided Microsoft propaganda regarding the string handling functions etc.

Unofficial recommendations by yours sincerely here: Which functions from the standard library must (should) be avoided?.

Upvotes: 2

Govind Parmar
Govind Parmar

Reputation: 21532

The following code is valid in C89, deprecated under C99, and invalid in C11 and further, due to its use of the unsafe function gets:

#include <stdio.h>

int main()
{
    char str[100];
    puts("What's your name?");
    gets(str);
    printf("Hello %s!\n", str);
}

Upvotes: 1

Related Questions