NO

Author Topic: get_s() usage warning  (Read 8017 times)

dizergin

  • Guest
get_s() usage warning
« on: March 10, 2015, 04:13:33 PM »
trivial
Code: [Select]
#include <stdio.h>
int main(int argc, char *argv[])
{
char b[100];
gets_s(b, sizeof b);
    printf("%s\n",b);
    return 0;
}
generates
Code: [Select]
Building main.obj.
[b]C:\Users\User\Documents\Pelles C Projects\mmm\asd\main.c(8): warning #2018: Undeclared function 'gets_s' (did you mean 'gets'?); assuming 'extern' returning 'int'.[/b]
Done.
compiler warning (with either c99 or c11 compatibility option)...
is it right?

on the other hand
Code: [Select]
#include <stdio.h>
int main(int argc, char *argv[])
{
char b[100];
gets(b);
    printf("%s\n",b);
    return 0;
}
with excluded gets() (under c11 option) compiles with the same warning.


« Last Edit: March 10, 2015, 04:22:39 PM by dizergin »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: get_s() usage warning
« Reply #1 on: March 10, 2015, 06:01:19 PM »
That's not a bug!
Please read other reports. To enable safe functions you have to define library extension __STDC_WANT_LIB_EXT1__.
With:
Code: [Select]
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
int main(int argc, char *argv[])
{
char b[100];
gets_s(b, sizeof b);
    printf("%s\n",b);
    return 0;
}
You will get no more warnings.
gets is deprecated.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

dizergin

  • Guest
Re: get_s() usage warning
« Reply #2 on: March 10, 2015, 06:56:03 PM »
That's not a bug!
Please read other reports. To enable safe functions you have to define library extension __STDC_WANT_LIB_EXT1__.
With:
Code: [Select]
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
int main(int argc, char *argv[])
{
char b[100];
gets_s(b, sizeof b);
    printf("%s\n",b);
    return 0;
}
You will get no more warnings.
gets is deprecated.
No Frankie, sorry
1. I were not sure about gets_s - so ask for possible explanation - thank you for!
2. It was depricated in the c99 standart, but in the c11 standart  it was excluded - so it is the bug, minor one... by the way,  with the c99 option the compiler produces "The function gets() is marked as depricated " - and it is true by all means.


yet, gets_s()  is recommended for usage instead gets() and it is included in the standart C library, so i can see  (at the first sight) no reason to protect it with ugly
 __STDC_WANT_LIB_EXT1__ 1
why (to say) Orinius did not put printf() under it...
« Last Edit: March 10, 2015, 08:54:57 PM by dizergin »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: get_s() usage warning
« Reply #3 on: March 10, 2015, 10:46:33 PM »
yet, gets_s()  is recommended for usage instead gets() and it is included in the standart C library, so i can see  (at the first sight) no reason to protect it with ugly
 __STDC_WANT_LIB_EXT1__ 1
why (to say) Orinius did not put printf() under it...
It is required by standard see for compliance tests. The preprocessor predefined macro __STDC_LIB_EXT1__ exists in PellesC.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

dizergin

  • Guest
Re: get_s() usage warning
« Reply #4 on: March 11, 2015, 01:55:41 AM »
yet, gets_s()  is recommended for usage instead gets() and it is included in the standart C library, so i can see  (at the first sight) no reason to protect it with ugly
 __STDC_WANT_LIB_EXT1__ 1
why (to say) Orinius did not put printf() under it...
It is required by standard see for compliance tests. The preprocessor predefined macro __STDC_LIB_EXT1__ exists in PellesC.
yes, yet  it is  end-user optional  and it was introduced in c11 (NOT C99), so C99 user must know nothing about it or not?

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: get_s() usage warning
« Reply #5 on: March 11, 2015, 11:55:37 AM »
yes, yet  it is  end-user optional  and it was introduced in c11 (NOT C99), so C99 user must know nothing about it or not?
Theoretically should not exist in C99, but why to remove it? It can be helpfull anyway. May we consider it a non standard C99 function?  ;)
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: get_s() usage warning
« Reply #6 on: March 11, 2015, 12:37:26 PM »
gets_s() exist in MSVC, so it should be available even before C11.
May the source be with you

dizergin

  • Guest
Re: get_s() usage warning
« Reply #7 on: March 11, 2015, 02:48:54 PM »
yes, yet  it is  end-user optional  and it was introduced in c11 (NOT C99), so C99 user must know nothing about it or not?
Theoretically should not exist in C99, but why to remove it? It can be helpfull anyway. May we consider it a non standard C99 function?  ;)
i talk another thing of!   - gets_s() is introduced as  PART OF STANDART ISO C LIBRARY (since C99). So EVERY program compiled with  C99 compliant compiler must proceed through without any warning upon!
Yet gets() was EXCLUDED from  STANDART ISO C LIBRARY (since C11) so any C11 compiler must generate ERROR upon (also C99 compiler must warn upon)!
Of course gets() may exist for backward compatibility (in C11 mode).. or as peculiar Pelles C  feature in this case it is matter of extenstion compiler option, extra library header, or protective macro definition ( just as  _USE_MATH_DEFINES for M_PI.... GNU C extension)
« Last Edit: March 11, 2015, 03:06:38 PM by dizergin »

dizergin

  • Guest
Re: get_s() usage warning
« Reply #8 on: March 11, 2015, 03:01:32 PM »
gets_s() exist in MSVC, so it should be available even before C11.
I think  It should for it is integral part ISO standart library since C99 and Pelles C claims itself to be ISO compliant. MS so far as I know has never been bothering itself about any compatibility with ISO... Yet in the last VS2013   they are almost wipe out C from regular projects...
« Last Edit: March 11, 2015, 03:04:34 PM by dizergin »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: get_s() usage warning
« Reply #9 on: March 11, 2015, 03:27:35 PM »
gets_s is not in WG14/N1124 document ?
What document you refer ?
May the source be with you

dizergin

  • Guest
Re: get_s() usage warning
« Reply #10 on: March 11, 2015, 04:22:13 PM »
gets_s is not in WG14/N1124 document ?
What document you refer ?
I just browse through a bunch documents with gets_s() - they are   :(  drafts. So as say Frankie "technically" - pure C99 compiler must warn on gets() (and Pelles C does) C11 must prohibit compiliation (Pelles C just warns).  Concerning gets_s()  both C99 and C11 compliants must prohibit compiliation (Pelles C passes with warning) like
Code: [Select]
#include <stdio.h>
int main(int argc, char *argv[])
{
    printf("%f",sqrt(2.0));
    return 0;
}
with the same message... and that is bug

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: get_s() usage warning
« Reply #11 on: March 11, 2015, 05:09:15 PM »
Just a moment you are missing something.
The warning/deprecation mechanism pass through the preprocessor and ISO headers, and an hedaer cannot block the compiler itself. This is correct because, while the standard library function gets() could be deprecated by ISO, no parts of the standard exclude taht you can create your own routine called gets() or any other function.
Moreover you can exclude standard libraries and header and compile something in native mode or whatever (I wrote a sample OS using PellesC that way, it is in contrubutions).
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

dizergin

  • Guest
Re: get_s() usage warning
« Reply #12 on: March 11, 2015, 06:07:36 PM »
Just a moment you are missing something.
The warning/deprecation mechanism pass through the preprocessor and ISO headers, and an hedaer cannot block the compiler itself. This is correct because, while the standard library function gets() could be deprecated by ISO, no parts of the standard exclude taht you can create your own routine called gets() or any other function.
Moreover you can exclude standard libraries and header and compile something in native mode or whatever (I wrote a sample OS using PellesC that way, it is in contrubutions).
I am aware of, but I talk about safety of the standart library level - just look upon sqrt() example - it is just passed by with no any math.h header declaration, on the other hand you can not reach out M_PI without redefinition or  _USE_MATH_DEFINES (defined within the same math.h header). Yet I were quite assured  that it is safe to make C program on std lib level...
« Last Edit: March 11, 2015, 11:13:35 PM by dizergin »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: get_s() usage warning
« Reply #13 on: March 12, 2015, 11:11:49 AM »
I see  :)
But C is not a strong checking language...  :)
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide