static vs dynamic cast
#1
I was wondering if there's a reason a number of places are using static_cast instead of dynamic_cast, and then checking for a null result?

There's quite a few places in the dialog code, but a simple example is this function:
https://github.com/xbmc/xbmc/blob/master...s.cpp#L490

My main query is the last null check, static cast will only return null if the data was null, which was already checked. However, dynamic cast would return null for the wrong type, which I'm wondering if that's actually the desired behaviour?

Should these kind of casts actually be dynamic casts? Or are the null checks redundant?
Reply
#2
That's probably the result of copy & pasting the first null pointer check into most of these setting option filler methods and not really looking at the rest of the code.

I chose to use static casts because (in the above case) if the data pointer is not of the type the data pointer is casted to it is a programming error. So the second null check is not really needed. The same could be argued for the first because if that method is called with the data pointer being NULL the developer did something wrong.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply

Logout Mark Read Team Forum Stats Members Help
static vs dynamic cast0