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

Fix a compile error when HAGL_HAL_DEBUG is not defined #56

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

SebKuzminsky
Copy link
Contributor

Before this commit, if the user did not define HAGL_HAL_DEBUG the project would fail to compile because hagl_hal_debug() was syntactically incorrect.

This commit fixes the error by providing a valid hagl_hal_debug() function both when HAGL_HAL_DEBUG is defined and not. When HAGL_HAL_DEBUG is defined it prints the debug message, just like now. When HAGL_HAL_DEBUG is not defined, the function does not do anything.

@tuupola
Copy link
Owner

tuupola commented Oct 23, 2023

Better way to fix this is to define HAGL_HAL_DEBUG if it is not defined. Ie. something like:

#ifndef HAGL_HAL_DEBUG
#define HAGL_HAL_DEBUG         (0)
#endif

@SebKuzminsky
Copy link
Contributor Author

Defining HAGL_HAL_DEBUG if it is not defined (as you suggested above) would work, but it's debatable whether that would be better. The solution proposed in this PR has the advantage that the compiler will optimize it out - there won't be any storage or runtime impact of hagl_hal_debug() statements.

But that said, i'd he happy to rework this PR to use your proposal if you prefer.

@tuupola
Copy link
Owner

tuupola commented Oct 23, 2023

Most compilers are smart enough to optimize out if (0) { ... }. See for example:

https://godbolt.org/z/qv77snYG4

@SebKuzminsky
Copy link
Contributor Author

I switched this branch to use your suggestion.

@tuupola tuupola changed the title fix a compile error when HAGL_HAL_DEBUG is not defined Fix a compile error when HAGL_HAL_DEBUG is not defined Oct 24, 2023
@tuupola tuupola merged commit 79418ad into tuupola:master Sep 4, 2024
@SebKuzminsky SebKuzminsky deleted the fix-no-HAGL_HAL_DEBUG branch September 4, 2024 15:53
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