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

Timestamp: Update workaround to support MinGW alongside MSVC #296

Merged
merged 6 commits into from
Dec 18, 2024

Conversation

Doekin
Copy link
Contributor

@Doekin Doekin commented Dec 14, 2024

Original

Timestamp: Replace strptime with std::get_time for better compatibility

The strptime function is a POSIX extension, not universally supported by all compilers (e.g., MSVC). Replacing it with std::get_time, which is part of the C++ standard, improves cross-platform compatibility without sacrificing functionality.

Edit

std::get_time has poor performance compared to strptime. My issue was that MinGW failed to compile reflect-cpp due to the lack of strptime. A more precise solution is to extend the existing workaround to cover MinGW, while keeping strptime for better performance on supported platforms.

@liuzicheng1987
Copy link
Contributor

Hi, my concern with the get_time solution is that strptime is more efficient. I'd rather only use strptime where possible and use the workaround where necessary.

Or is there any specific problem you encountered because of that?

@Doekin
Copy link
Contributor Author

Doekin commented Dec 15, 2024

Hi,
I encountered a compilation issue while using reflect-cpp with MinGW:

error: use of undeclared identifier 'strptime'

Since strptime is a POSIX extension, it isn’t universally supported and may require additional workarounds for certain platforms. Using a standard function like std::get_time would improve cross-platform compatibility out of the box.

That said, I understand your concern about efficiency. I’ll run a benchmark to evaluate the performance difference and see if the trade-off is reasonable. Let me follow up with the results soon.

@Doekin
Copy link
Contributor Author

Doekin commented Dec 15, 2024

A quick benchmark shows std::get_time is quite slower than strptime. Sorry, I should’ve looked into this performance difference earlier.

@liuzicheng1987
Copy link
Contributor

@Doekin, no problem. Let's try to resolve your issue by finding a macro that captures your case as well.

@Doekin Doekin changed the title Timestamp: Replace strptime with std::get_time for better compatibility Timestamp: Update workaround to support MinGW alongside MSVC Dec 15, 2024
@Doekin
Copy link
Contributor Author

Doekin commented Dec 15, 2024

x86_64-w64-mingw32-gcc defines both __MINGW32__ and __MINGW64__. It seems that using __MINGW32__ might be sufficient to capture this case.

@Doekin Doekin force-pushed the Timestamp-strptime branch from 3e6709a to ad12d2d Compare December 15, 2024 13:08
@liuzicheng1987 liuzicheng1987 merged commit fe8a5c5 into getml:main Dec 18, 2024
9 checks passed
@liuzicheng1987
Copy link
Contributor

@Doekin, merged. Thanks for your contribution!

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.

2 participants