Fix -WSign warning in battle_transition#2274
Conversation
src/battle_transition.c:1199:16: warning: passing 'u16[960]' (aka 'unsigned short[960]') to parameter of type 's16 *' (aka 'short *') converts between pointers to integer types with different sign [-Wpointer-sign] 1199 | SetSinWave(gScanlineEffectRegBuffers[1], sTransitionData->cameraX, 0, 2, 0, 160);
|
Ping |
|
I feel like this PR lacks context. Can you explain why it's correct for the type of the first argument to |
Because the pointer we pass as the first argument is a u16 pointer. It just fixes a clang warning. Not sure if it is technically UB. But I feel like if clang is warning about it, it probably is. |
|
As far as I know, changing the type pointed to between signed and unsigned is not UB by itself, but dereferencing it would probably fall under conversion between signed and unsigned, where the typical rules apply: conversion from signed to unsigned is always well-defined, conversion from unsigned to signed is well-defined if the value can be represented by the signed type, otherwise it is implementation-defined. |
|
imo I suppose it's debatable whether any hardware registers are signed or not, but LCD I/O BG Rotation/Scaling are clearly 2s complement, which I'd say translates to signed in C on the GBA:
I definitely don't think it makes sense to consider the output of |
src/battle_transition.c:1199:16: warning: passing 'u16[960]' (aka 'unsigned short[960]') to parameter of type 's16 *' (aka 'short *') converts between pointers to integer types with different sign [-Wpointer-sign]
1199 | SetSinWave(gScanlineEffectRegBuffers[1], sTransitionData->cameraX, 0, 2, 0, 160);