Guild icon
Teeworlds
discord.gg/teeworlds / development
For discussions around the development of the official Teeworlds
Between 2022-03-29 00:00:00Z and 2022-03-30 00:00:00Z
Avatar
@Assa as I can't answer in bridge
20:11
#include <iostream> class CTest { int a; int b; int c; int d; }; int main() { std::cout << "sizeof(CTest) : " << sizeof(CTest) << std::endl; std::cout << "sizeof(int) : " << sizeof(int) << std::endl; std::cout << "sizeof(CTest) / sizeof(int) : " << sizeof(CTest) / sizeof(int) << std::endl; }
20:11
sizeof(CTest) : 16 sizeof(int) : 4 sizeof(CTest) / sizeof(int) : 4
20:12
CTest has its size equals to each member size (dunno how to say it in english)
20:12
4 ints, then CTest = 16 bytes
20:12
basically Num() gives the number of members in that class
Avatar
i understood how it works, but it's still hackish
Avatar
well it's cool
Avatar
and also the type was wrong in the link
Avatar
just not quite clear that part of the code
Avatar
@ReiTW's example is fine and not fragile imo
20:13
that in teeworlds code looks bad to me, it uses int instead of char*
Avatar
why should it be char *
20:14
the s_apNames is static
Avatar
@Dune the Macro defines CTuneParam instances, which are integer warappers
Avatar
isn't CTuningParams just static const char *s_apNames[];
20:14
no
20:14
it's defined in the macro
20:15
the static variable doesn't increase the size of the object
Avatar
ahhh, it's static, nvm
20:15
right, then it's fine I guess
Avatar
should still be sizeof (CTuneParam) and not int
20:16
If that datatype ever changes this code will break
Avatar
CTuneParam &operator = (int v) { m_Value = (int)(v*100.0f); return *this; } works too but v is already an integer
Avatar
yes master
Avatar
not super readable
Exported 30 message(s)