LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Workaround: incomplete __int64 support in stdio library

Hey guys,
  For those of you who aren't aware of it yet, the stdio library doesn't fully support __int64 variables in formatting specifiers.  Very specifically, the sprintf() function--perhaps the entire printf() family--will not let you format an __int64 into a string.
  NI gave me a workaround today by moving me over to the Fmt() family of functions in the formatio library (in place of sprintf()).  If you will be doing this type of conversion in your future CVI-developed software, please take note and save yourself some time of banging your head against the wall.  Here is an example of __int64 formatting that works as expected, as discovered through my service request today.
 
#include <utility.h>
#include <formatio.h>

__int64 number = 12345;
char mystring[50];
Fmt (mystring, "%s<%i[b8]", number);

  There doesn't appear to be any way to do this properly with sprintf().  I doubt if the scanf() family works either--but I have not tried it yet.  Perhaps this is a C89 vs. C99 thing.  Personally, I think this was an oversight going as far back as CVI 7 but it is quite frustrating.  This should either be corrected in the CVI 8.0.2 maintenance release or NI needs to clarify on all CVI webpages (including product advertisements) that __int64 support continues to be cursory.
 
Orlan
Message 1 of 4
(4,708 Views)

You can use the I64 modifier to specify 64 bit integer format specifiers in the stdio library. For example:

__int64 i64;

unsigned __int64 ui64;

printf("%I64d, %I64u", i64, ui64);

Message 2 of 4
(4,697 Views)
Thanx Mohan,
  I fully retract my post then.  I opened an SR yesterday and this solution was not provided to me.  I was told to use Fmt() instead.  Can NI post this into the CVI help files somewhere so that all of the format specifiers are clearly identified?
 
Orlan

Message Edited by cosmo on 06-06-2006 10:21 AM

Message 3 of 4
(4,687 Views)
Thanks for taking the time to post this tidbit of information Cosmo.  And thanks to Mohan for the updated information.   I learn something new here every day.
Message 4 of 4
(4,669 Views)