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 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3447 |
| 6 | Um_nik | 3387 |
| 7 | heuristica | 3322 |
| 8 | turmax | 3317 |
| 9 | tourist | 3307 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 141 |
| 5 | Errichto | 139 |
| 6 | adamant | 137 |
| 7 | AmShZ | 135 |
| 8 | BledDest | 132 |
| 9 | maroonrk | 131 |
| 10 | qwexd | 129 |
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.
defineis low-level preprocessing construct which will blindly replace allLLtokens withlong long intregardless of their meaning before compiler even gets a chance to take a look at the code.typedefworks on compiler level, it tells compiler to make a new type calledLLand 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:
inlinesuggests 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 discardinlinemodifier 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
#definecannot 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.