Hello Everyone,
What's the difference in these two macros ?
#define LL long long int
and
typedef long long LL;
and
What's the difference between these ?
inline void myFunction(){}
and
void myFunction(){}
Thanks !
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hello Everyone,
What's the difference in these two macros ?
#define LL long long int
and
typedef long long LL;
and
What's the difference between these ?
inline void myFunction(){}
and
void myFunction(){}
Thanks !
Name |
---|
Auto comment: topic has been updated by vkditya0997 (previous revision, new revision, compare).
For the first one look here.
define
is low-level preprocessing construct which will blindly replace allLL
tokens withlong long int
regardless of their meaning before compiler even gets a chance to take a look at the code.typedef
works on compiler level, it tells compiler to make a new type calledLL
and make it same aslong long
, so it won't screw up some other places (see the link for a good example).For the second one: here. Actually, there is little difference:
inline
suggests that compiler inline that function wherever it's called instead of pushing arguments to stack and making a jump, can save some time. But it's still only suggestion, compiler is free to do anything it wants: both discardinline
modifier and inline function without that modifier. There is some serious difference on linking stage, but that does not matter in competitive programming.Some contestants inline every function they use. Is it appropriate?
It does not hurt.
Inline? Check this vs this.
One clear practical difference is that names introduced by
#define
cannot be used in other contexts in the program. For example:Wow, you made my day. Until now I thought that this would not compile with typedef either, but all this C++ namespace and scope stuff can sometimes be ridiculous.
The code below compiles successfully (at least by g++4-8):
Standard name lookup rules apply to your example. It compiles for the same reason why the next example compiles — because the inner scope is always looked up first unless the
::
operator is used:And the other way around: trying to define a variable and a type in the same scope with the same name leads to an error.