Qualified's blog

By Qualified, history, 5 years ago, In English

Is there a difference in time between the two methods? Which one is better and why?

  • Vote: I like it
  • +21
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it +25 Vote: I do not like it

There is no difference in time, but using #define ll long long is not recommended by specifications, you should use typedef for defining types.

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +32 Vote: I do not like it

    or try

    using ll = long long;
    

    It's easier to understand! Though I always end up using #define because of my bad practices :(

  • »
    »
    5 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Neither define nor typedef defines a new type.

»
5 years ago, # |
  Vote: I like it +28 Vote: I do not like it

The syntax using ll = long long; is more modern.

For a simple type definition it does exactly the same as typedef long long ll;

But using supports template parameters, so the concept is more powerful. In example the following definition does not work good with typedef.

template<typename T>
using MyList = std::list<T, MyAlloc<T>>;

MyList<Sometype> myList;

Since a typedef does not support template parameters we would need to 'misuse' a struct, something like this:

template<typename T>
struct MyList {
  typedef std::list<T, MyAlloc<T>> type;
};

MyList<Sometype>::type myList;
  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks! But which one would you recommend?

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +2 Vote: I do not like it

      Until some hours ago I used typedef, then did read your post, did read about the topic...and decided to use using.

»
5 years ago, # |
  Vote: I like it +97 Vote: I do not like it

Both of these are wrong. Use #define int long long =)

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Why int long long is bad? (I don't know)

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it +4 Vote: I do not like it

      Well sometimes it causes TLE because the processing time for long long is 2 times that of int and the statement changes all int to long long, so after continuous use of #define int long long you kind of forget that it's there, and with problems with tight time limit bound you end up getting a TLE ( but after 1 or 2 TLE's you kind of become vigilante :p )

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it +1 Vote: I do not like it

        thanks to reply

      • »
        »
        »
        »
        5 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        A lot of simple 64-bit operations are one clock cycle if you submit with C++17 (64). In the time I've used #define int long long in my template, it hasn't caused me any trouble in MLE/TLE, and has saved me many times from unexpected overflow.

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it +8 Vote: I do not like it

          Well you can't expect every website to be as upto date as CF, even Google competitions don't have c++17 as far as I remember :)

        • »
          »
          »
          »
          »
          5 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          remember to writesigned main()

»
5 years ago, # |
  Vote: I like it +36 Vote: I do not like it

print long long manually until you're master

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Use using ll = long long.

It will replace ll with long long only in contexts where ll is a type. It also makes a real type-level type alias.

#define ll long long will blindly replace ll token with long long tokens everywhere in your code even if it does not make sense. In particular, you won't be able to write ll(10.5) with #define as you could with other types like int(10.5).

»
4 months ago, # |
  Vote: I like it -15 Vote: I do not like it

I always use "define int long long"^~^