0

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?

Undefined Behavior
  • 2,128
  • 4
  • 24
  • 34
  • 2
    Yes; the `gets` function is the biggest example – Govind Parmar Nov 22 '18 at 16:17
  • 1
    ...which is mentioned in the [Wikipedia article for C11](https://en.wikipedia.org/wiki/C11_(C_standard_revision)#Changes_from_C99). – Robert Harvey Nov 22 '18 at 16:18
  • 1
    `gets` is not only depracated in C11, but in fact completely removed. The changes can be found in the appendixes of each standard document. – DeiDei Nov 22 '18 at 16:26
  • 2
    Possible duplicate of [Compatibility of C89/C90, C99 and C11](https://stackoverflow.com/questions/41535927/compatibility-of-c89-c90-c99-and-c11) – Swordfish Nov 22 '18 at 16:26

2 Answers2

2

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?.

Lundin
  • 195,001
  • 40
  • 254
  • 396
1

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);
}
Govind Parmar
  • 20,656
  • 7
  • 53
  • 85