22.12.2012, 14:22
Today I learned (more realised) that you can do:
Instead of:
Or the more stupid:
That way you get the compiler to do the lengths for you (assuming of course that you want the length - this is just one example) instead of miscounting or forgetting to update it. I've also previously written about why using "stock const"s are better than straight string literals here:
https://sampforum.blast.hk/showthread.php?tid=216730
So this is just an added bonus.
pawn Code:
stock const STR[] = "hi";
main()
{
if (strcmp(STR, OTHER_STRING, false, sizeof (STR) - 1) {}
}
pawn Code:
main()
{
if (strcmp("hi", OTHER_STRING, false, 2) {}
}
pawn Code:
main()
{
if (strcmp("hi", OTHER_STRING, false, strlen("hi")) {}
}
https://sampforum.blast.hk/showthread.php?tid=216730
So this is just an added bonus.