Home > Blockchain >  Using of Strfromd/strfromf in C for converting to string without using snprintf : warning: implicit
Using of Strfromd/strfromf in C for converting to string without using snprintf : warning: implicit

Time:01-26

I'm exploring the usage strfromd, strfromf functions as an alternative for snprintf for converting double, integer to string values respectively in my C code. (I'm using Oracle virtual machine Ubuntu 20.04 version for build purposes.)

I have included

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

in my code but I'm getting the following warnings during compilation:

warning: implicit declaration of function ‘strfromd’ [-Wimplicit-function-declaration] during compilation.,
warning: implicit declaration of function ‘strfromf’ [-Wimplicit-function-declaration]

I'm able to remove this warning in my PC by declaring:

int strfromd(char *restrict str, size_t n,const char *restrict format, double fp);
int strfromf(char *restrict str, size_t n,const char *restrict format, float fp);

at the top of my code (not sure if it is a right way) and warning is resolved with this particular change in my VM but when tried in a different environment, I'm getting error - undefined reference to 'strfromd' error and my build crashes.

Does anyone face similar issues while using any of the strfromd/strfromf/strfroml functions and what can be done to remove these issues for code execution?

NOTE: I already tried below exercise:

#define __STDC_WANT_IEC_60559_BFP_EXT__
#include <stdlib.h>

The warning is resolved in my VM but still gives an undefined reference to 'strfromd' error in the other environment.

CodePudding user response:

Per the strfromd(3) man page:

The strfromd(), strfromf(), and strfroml() functions are available in glibc since version 2.25.

So your system needs to have a version of glibc at version 2.25 later.

In addition, you should also #define __STDC_WANT_IEC_60559_BFP_EXT__:

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

  strfromd(), strfromf(), strfroml():
      __STDC_WANT_IEC_60559_BFP_EXT__

CodePudding user response:

Try adding define for __STDC_WANT_IEC_60559_BFP_EXT__ before inclusion of stdlib.h like this:

#define __STDC_WANT_IEC_60559_BFP_EXT__
#include <stdlib.h>

BTW, do not credit me, credit the man page of 'strfromd'

  •  Tags:  
  • Related