pointer-type args: cast appropriately to be 64-bit compatible
Using void pointers as universal arguments is widely used. However, when compiling a 64-bit target, the compiler doesn't like when an int is converted to a pointer and vice versa despite the presence of a cast. This is due to a width mismatch between ints (32 bits) and pointers (64 bits). The trick is to cast to a widening integer type such as intptr_t and then cast to void*. When appropriate, the INT_TO_POINTER macro is used instead of this double cast to make things clearer. The converse with POINTER_TO_INT is also done which also serves as good code annotations. While at it, remove unneeded casts to specific pointer types from void* in the vicinity, and move to typed variable upon function entry to make the code cleaner. Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
parent
5f5c9a5962
commit
6311766d9a
24 changed files with 120 additions and 112 deletions
|
@ -1156,9 +1156,9 @@ static void kill_handler(const struct shell *shell)
|
|||
void shell_thread(void *shell_handle, void *arg_log_backend,
|
||||
void *arg_log_level)
|
||||
{
|
||||
struct shell *shell = (struct shell *)shell_handle;
|
||||
struct shell *shell = shell_handle;
|
||||
bool log_backend = (bool)arg_log_backend;
|
||||
u32_t log_level = (u32_t)arg_log_level;
|
||||
u32_t log_level = POINTER_TO_UINT(arg_log_level);
|
||||
int err;
|
||||
|
||||
err = shell->iface->api->enable(shell->iface, false);
|
||||
|
@ -1220,7 +1220,7 @@ int shell_init(const struct shell *shell, const void *transport_config,
|
|||
k_tid_t tid = k_thread_create(shell->thread,
|
||||
shell->stack, CONFIG_SHELL_STACK_SIZE,
|
||||
shell_thread, (void *)shell, (void *)log_backend,
|
||||
(void *)init_log_level,
|
||||
UINT_TO_POINTER(init_log_level),
|
||||
K_LOWEST_APPLICATION_THREAD_PRIO, 0, K_NO_WAIT);
|
||||
|
||||
shell->ctx->tid = tid;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue