Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of "lg" in printf format #102

Merged
merged 2 commits into from
Dec 23, 2016
Merged

Remove usage of "lg" in printf format #102

merged 2 commits into from
Dec 23, 2016

Conversation

brarcher
Copy link
Contributor

@brarcher brarcher commented Dec 22, 2016

MinGW on Windows does not "lg". The reason is that MinGW mixes
GCC and the MSVC runtime. For GCC a long double is either
96-bit or 128-bit type for long double on x86 or x64 targets
(see http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html).
However, MSVC uses a 64-bit type
(see http://msdn.microsoft.com/en-us/library/9cx8xs15.aspx).
That means for MSVC "double" and "long double" are the same.

Because of this mismatch, the "l" in "lg", which is safely ignored
on Linux and BSD systems is not safely ignored in MSVC systems
where GCC is used to compile. This issue does not arise when using
VS compiler on Windows.

Credit for explaining this problem goes here: http://stackoverflow.com/questions/7134547/gcc-printf-and-long-double-leads-to-wrong-output-c-type-conversion-messes-u

#101

@brarcher
Copy link
Contributor Author

@9fcc This change fixes the issue with MinGW and does not change the output of any of the tests. The MinGW tests are now enabled.

Can you review the change?

@@ -673,7 +673,7 @@ CK_DLL_EXP void CK_EXPORT _ck_assert_failed(const char *file, int line,

/* Number of digits after the decimal point to output via printf */
#ifndef CK_FLOATING_DIG
# define CK_FLOATING_DIG 6
# define CK_FLOATING_DIG "6"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like an idea that precision might be a string. It gives users possibility to add hacks to Checks... And I am sure that somebody will use this possibility for their needs while it would lead problems afterwards. Writing 06, +6 would cause different situations too.
But using #CK_FLOATING_DIG would cause more problems since it would be the same as string in fact.

@9fcc
Copy link
Contributor

9fcc commented Dec 22, 2016

If there is no way to pass number for precision than changes are good to go.

MinGW on Windows does not "lg". The reason is that MinGW mixes
GCC and the MSVC runtime. For GCC a long double is either
96-bit or 128-bit type for long double on x86 or x64 targets
(see http://gcc.gnu.org/onlinedocs/gcc/i386-and-x86_002d64-Options.html).
However, MSVC uses a 64-bit type
(see http://msdn.microsoft.com/en-us/library/9cx8xs15.aspx).
That means for MSVC "double" and "long double" are the same.

Because of this mismatch, the "l" in "lg", which is safely ignored
on Linux and BSD systems is not safely ignored in MSVC systems
where GCC is used to compile. This issue does not arise when using
VS compiler on Windows.
@brarcher brarcher changed the title Remove usage of "%.*" and "lg" in printf format Remove usage of "lg" in printf format Dec 22, 2016
@brarcher
Copy link
Contributor Author

Removing just the "l" from "lg" was enough to resolve the issue. The precision change was unnecessary.

@brarcher
Copy link
Contributor Author

Jenkins: test this please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants