-
February 18th, 2024, 04:23 AM
#1
Is this valid for printf (in MSVC)
I'm trying to run a program that runs fine when built with gcc - and it builds okay with MSVC but crashes at run time.
I've traced the crash to a call to vsnprintf() which is getting passed a string like this:- "(Value: %s%s %+05.1lf dB) "
I've never seen %+05.1lf in a string before - is it a valid argument for MSVC?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
February 18th, 2024, 05:41 AM
#2
Re: Is this valid for printf (in MSVC)
Yes. See:
Code:
int main() {
printf("%+05.1lf\n", 1.456);
printf("%+05.1lf\n", 123.456);
printf("%+05.1lf\n", -13.456);
}
which displays:
+ means displays + for +ve numb and - for -ve numb
0 means pad with 0
5.1 is width of 5 with 1 digit precision
lf means long double
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 18th, 2024, 06:12 AM
#3
Re: Is this valid for printf (in MSVC)
Thanks 2kaud - has it always been like that or is this something new - e.g. C17 or whatever ?
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
February 18th, 2024, 07:07 AM
#4
Re: Is this valid for printf (in MSVC)
It's always been like that except that "%lf" came with c99/C++11 when long double was introduced. Note that that MS VS double and long double are the same.
PS. Why are we both working on a Sunday morning ??
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
February 18th, 2024, 07:15 AM
#5
Re: Is this valid for printf (in MSVC)
Haha - quite right!
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
March 3rd, 2024, 02:02 PM
#6
Re: Is this valid for printf (in MSVC)
Seems like this site's taken a backwards step again (believe it or not, it's only just notified me of 2kaud's replies from a fortnight ago !! )
"A problem well stated is a problem half solved.” - Charles F. Kettering
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|