<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Problems with function gcvt in stdlib.h library</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/97358/problems-with-function-gcvt-in-stdlib-h-library</link><description>Hi, i was trying to cast a float variable (temperature) in a char variable using the function gcvt (double,int,char *), but i faced some problems when i call it in the program. 
 i&amp;#39;m trying to do this beacause i need to send that temperature value trought</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Mar 2023 12:07:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/97358/problems-with-function-gcvt-in-stdlib-h-library" /><item><title>RE: Problems with function gcvt in stdlib.h library</title><link>https://devzone.nordicsemi.com/thread/414359?ContentTypeID=1</link><pubDate>Thu, 09 Mar 2023 12:07:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04d2da9d-5798-4364-a298-6e6416dc2842</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I must have missed that warning when I tested my example, I now see it here as well.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Discussing this with the developers it seems that this function has been deprecated, and now the recommended alternative is to use the sprintf(..) function instead.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I modified my own test example to use sprintf(..) instead, and you will find the example attached:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/304046_5F00_blinky_5F00_sprintf_5F00_test.zip"&gt;devzone.nordicsemi.com/.../304046_5F00_blinky_5F00_sprintf_5F00_test.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please note that some additional configs are needed in order to support floating point operations with sprintf(..).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also, if you want to convert float rather than double just replace &amp;quot;%.*g&amp;quot; with &amp;quot;%.*f&amp;quot;&lt;/p&gt;
&lt;p&gt;One odd thing I noticed is that for double conversions the number of digits is one less than the number provided in the num_digits variable, but in your application I assume you can just hard code this number anyway.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with function gcvt in stdlib.h library</title><link>https://devzone.nordicsemi.com/thread/414240?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 19:52:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c740cc2-b646-4885-ad76-fc9b12e1cf2e</guid><dc:creator>simon8</dc:creator><description>&lt;p&gt;i tried your sample and works fine.&lt;/p&gt;
&lt;p&gt;the only thing is that&amp;nbsp;when i open your project it works fine but there is a warning over the gcvt function that say:&lt;/p&gt;
&lt;p&gt;implicit declaration of function &amp;#39;gcvt&amp;#39; [-Wimplicit-function-declaration]&lt;/p&gt;
&lt;p&gt;if i go to stdlib.h intellisense&amp;nbsp;&lt;span&gt;continue to not find the function saying the function definition was not found.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;i don&amp;#39;t know why...&lt;/p&gt;
&lt;p&gt;if i try to implement gcvt in the original project it doesn&amp;#39;t work... when i flash and run it resets itself...&lt;/p&gt;
&lt;p&gt;i tried also gcvtf, cause is the more approrpiate function since i work with float values, but the sema problem of reset come out...&lt;/p&gt;
&lt;p&gt;i also tried this in your project, to find out if gcvtf works fine:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;int&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;ret&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(!&lt;/span&gt;&lt;span&gt;device_is_ready&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;led&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;port&lt;/span&gt;&lt;span&gt;)) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;ret&lt;/span&gt;&lt;span&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span&gt;gpio_pin_configure_dt&lt;/span&gt;&lt;span&gt;(&amp;amp;&lt;/span&gt;&lt;span&gt;led&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span&gt;GPIO_OUTPUT_ACTIVE&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;span&gt;ret&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;lt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;printk&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Blinky gcvt() test&lt;/span&gt;&lt;span&gt;\n&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;double&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;dval&lt;/span&gt;&lt;span&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span&gt;3.1415&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;float&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;fval&lt;/span&gt;&lt;span&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span&gt;23.324&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;uint8_t&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;16&lt;/span&gt;&lt;span&gt;];&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;gcvt&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;dval&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span&gt;6&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;//gcvtf(fval,6,buf);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;printk&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;Float conversion:&amp;nbsp;&lt;/span&gt;&lt;span&gt;%s&lt;/span&gt;&lt;span&gt;\n&lt;/span&gt;&lt;span&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;usb_enable&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;NULL&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;while&lt;/span&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;ret&lt;/span&gt;&lt;span&gt;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span&gt;gpio_pin_toggle_dt&lt;/span&gt;&lt;span&gt;(&amp;amp;&lt;/span&gt;&lt;span&gt;led&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;if&lt;/span&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;span&gt;ret&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;lt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;return&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;k_msleep&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;SLEEP_TIME_MS&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;it doesn&amp;#39;t... it only resets each time the while cycle is done&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;do i need to&amp;nbsp;enable other standard C libraries?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;this is what it looks like the sdtlib.h part where there are gcvt functions:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1678305054457v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;tree points that state:&amp;nbsp;&lt;span&gt;function saying the function definition was not found&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;i don&amp;#39;t know where to look for solutions...&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with function gcvt in stdlib.h library</title><link>https://devzone.nordicsemi.com/thread/414020?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 08:28:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92a188c2-2d08-421d-a84e-ea516113b968</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It worked fine on my end, yes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I just tried it again in v2.1.2 of the SDK and using the nrf5340dk_nrf5340_cpuapp board, to keep the test closer to your setup, and it still works fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You will find my test app attached, I simply modified the blinky sample in the SDK:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/304046_5F00_blinky_5F00_gcvt_5F00_test.zip"&gt;devzone.nordicsemi.com/.../304046_5F00_blinky_5F00_gcvt_5F00_test.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with function gcvt in stdlib.h library</title><link>https://devzone.nordicsemi.com/thread/413868?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2023 14:00:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29e7fb38-99b5-4346-ae3c-3c34edd74932</guid><dc:creator>simon8</dc:creator><description>&lt;p&gt;i&amp;#39;ve just done that, but the same problem occurs...&lt;/p&gt;
&lt;p&gt;did you try that and works fine?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problems with function gcvt in stdlib.h library</title><link>https://devzone.nordicsemi.com/thread/413797?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2023 11:53:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:457451f0-78cd-4d85-88cd-ffa60d152c1e</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Probably you just need to enable the standard C library in your project. To do so please add the following line to your project configuration (prj.conf):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;CONFIG_NEWLIB_LIBC=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>