-1

I don’t know why use this using i64 = long long; in C++ contest.

What’s the reason behind using this?

Chris
  • 26,361
  • 5
  • 21
  • 42
  • 1
    It permits one to write more terse code. – Chris Sep 13 '22 at 05:59
  • 3
    Some people believe fewer keystrokes are "more better". They'll copy/paste worthlessly abbreviated type aliases, many of which they won't even use, in a cookie-cutter-contests-make-me-uber mentality. They're wrong, btw. *clarity* is better. And the only contest worth fighting for is the one that puts digits on your paycheck, and you don't do that by writing obfuscated code. – WhozCraig Sep 13 '22 at 06:01
  • 1
    @WhozCraig Are you saying that `long long` is clearer that it's a 64 bit integer than `i64`? Because I would disagree. – gre_gor Sep 13 '22 at 06:08
  • 5
    @gre_gor If one wants a type with exactly 64 bits, then one should use `std::int64_t` and then the argument for whether or not it makes sense to alias that to `i64` applies again. Aliasing or using `long long` as 64bit type seems already wrong given that there are fixed-width types. It makes implicit assumptions about the platform that can easily be avoided. – user17732522 Sep 13 '22 at 06:13
  • @user17732522 exactly. if I want a 64-bit integer *and* clarity in doing so, I'll include `` and use `std::int64_t` which speaks for itself, not cross my fingers and hope `long long` is definitive to 64 bits (which is the normative *minimum*, but that's all). – WhozCraig Sep 13 '22 at 06:30

3 Answers3

2

The line

using i64 = long long;

creates a type alias for the integer type long long that is called i64.

However, this alias implies that long long would be a 64-bit integer, which is not precise. The standard requires long long to be at least 64 bits, if you need exactly 64 bits, use the fixed width integer type int64_t.

Lukas-T
  • 11,133
  • 3
  • 20
  • 30
0

This is a type alias. From the cpp-reference:

A type alias declaration introduces a name which can be used as a synonym for the type denoted by type-id. It does not introduce a new type and it cannot change the meaning of an existing type name.

The line

using i64 = long long;

implies that i64 maybe used to refer to the type long long proceeding the using statement within the scope.

However, as @churill's answer clarifies, in this case, using i64 as an alias for long long is misleading and should be avoided.

Standard_101
  • 325
  • 4
  • 14
-1

You just give a name for "long long" type. In your program every "i64" are simply being replaced by "long long" type. You can use "long long" instead of "i64" and there will be no difference.

Hackjaku
  • 84
  • 1
  • 10
IncPink
  • 34
  • 4
  • 3
    "[Y]ou want to use short names instead of longer names" is a bad advice. Using more semantically specific names is good. Using shorter names without semantic context leads to obfuscated code that is harder to read, understand and maintain. – Some programmer dude Sep 13 '22 at 06:03