threadx icon indicating copy to clipboard operation
threadx copied to clipboard

Consider declaring the name of the entities as "CHAR const *" instead of "CHAR *"

Open pirgia opened this issue 1 year ago • 4 comments

The functions that create an entity (thread, semaphore, etc.), take the entity's name as CHAR*. I believe that, as the name isn't likely to change, the constness of the name (in the structures and the parameters) would be a nice to have feature. But the reason of the request is that, while it is allowed in "C" to pass a constant string to a "char *" parameter, in C++ (starting from C++11) it is not allowed to pass a string literal (constant) to a "char *" parameter (ISO C++ forbids converting a string constant to 'CHAR *'). The latter forces the user (interfacing a C++ application with ThreadX) to const-cast the name of the entity, something like:

tx_thread_create(&thread1, const_cast<char*>("Thread name"),....);

which is ugly and, above all, not recommended by many coding standards. I'd like to know your opinion. Thanks for your attention.

pirgia avatar Apr 29 '24 07:04 pirgia

Fully support this. It should have been done from the day 1.

MaJerle avatar Apr 29 '24 08:04 MaJerle

This is an issue which has been raised and discussed earlier. Refer to https://github.com/eclipse-threadx/threadx/issues/61

hwmaier avatar Apr 29 '24 08:04 hwmaier

Thankfully we have now a PR to address this long standing issue. Refer to https://github.com/eclipse-threadx/threadx/pull/414

hwmaier avatar Oct 02 '24 22:10 hwmaier

I requested a review on the PR, @hwmaier. If it is positive, this feature will likely be part of ThreadX v6.4.3.

fdesbiens avatar Feb 27 '25 16:02 fdesbiens