Const vs Define
#1

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.
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);
}
2.
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);
}
Edit: Silly me, fixed the examples.
Reply


Messages In This Thread
Const vs Define - by Finn - 13.07.2012, 18:08
Re: Const vs Define - by Vince - 13.07.2012, 18:30
Re: Const vs Define - by Roko_foko - 13.07.2012, 18:47
Re: Const vs Define - by milanosie - 13.07.2012, 18:50
Re: Const vs Define - by Finn - 13.07.2012, 18:57
Re: Const vs Define - by Roko_foko - 13.07.2012, 19:03

Forum Jump:


Users browsing this thread: 1 Guest(s)