13.07.2012, 18:08
After reading the Useful Snippets thread today, I got totally confused with the pros & cons of defines and constants.
So, I'm looking for an answer to this question: Which code below is better and why?
1.
2.
Edit: Silly me, fixed the examples.
So, I'm looking for an answer to this question: Which code below is better and why?
1.
pawn Код:
#define THIS "this or that"
main()
{
new string[128], rand = random(100);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
format(string, sizeof(string), "I like " THIS " a lot also I like the number %d.", rand);
print(string);
}
pawn Код:
static const THIS[] = "this or that";
main()
{
new string[128], rand = random(100);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
format(string, sizeof(string), "I like %s a lot also I like the number %d.", THIS, rand);
print(string);
}