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 TRICE_OFF #433

Merged
merged 1 commit into from
Sep 21, 2023
Merged

fix TRICE_OFF #433

merged 1 commit into from
Sep 21, 2023

Conversation

JannisKonradBecker
Copy link
Contributor

with TRICE_OFF defined, trice.h redefines TRICE_ENTER and TRICE_LEAVE

@rokath
Copy link
Owner

rokath commented Sep 20, 2023

Thanks, for the pull request. Why did you change line 182 as well? (restrict --> __restrict)

@JannisKonradBecker
Copy link
Contributor Author

sorry, that is an unrelated problem. When including trice.h from c++ code gcc throws this error:

trice/trice.h:193:32: error: expected ',' or '...' before 'output'
  193 | int TCOBSEncode(void* restrict output, const void* restrict input, size_t length);

@rokath
Copy link
Owner

rokath commented Sep 21, 2023

That´s interesting. In trice.h line 8-10 is

#ifdef __cplusplus
extern "C" {
#endif

Usually I avoid C++ because all of its nuts and bolts. I could extend the code around line 182 into

#ifdef __cplusplus
int TCOBSEncode( void * __restrict output, const void * __restrict input, size_t length);
#else
int TCOBSEncode( void * restrict output, const void * restrict input, size_t length);
#endif

but I assume that´s not the way to do it. Any proposal?

@JannisKonradBecker
Copy link
Contributor Author

I don't see a problem with that solution.

extern "C" only defines C linkage, not C syntax sadly.

__restrict works for GCC in C and C++ mode.
Other C++ compilers might not like restrict at all.

Would this cause Problems?

#ifdef __cplusplus
int TCOBSEncode( void * output, const void * input, size_t length);
#else
int TCOBSEncode( void * restrict output, const void * restrict input, size_t length);
#endif

restrict is still defined in the c file so that code should still be optimized and GCC doesn't complain.

@rokath rokath merged commit 51dca5c into rokath:master Sep 21, 2023
1 check failed
@rokath
Copy link
Owner

rokath commented Sep 21, 2023

For now I added this line to triceConfig.h:

#define RESTRICT restrict //!< Adapt it to your compiler: restrict, __restrict, __restrict__ or empty

and changed all occurances of restrict to RESTRICT to avoid the additional #ifdef __cplusplus. I do not like this very much but this allows the users to use the library without modifying the code.

@JannisKonradBecker
Copy link
Contributor Author

Sounds like a good Solution, thanks.

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