2

I was reading some C++ code and I came across this rather strange line.

This is the line:

if (!k || !n || !m) return min((ll)tot, m*(1LL << n));

The 1LL seems to have been answered here: What is 1LL or 2LL in C and C++?

What i'm wondering is what exactly the (ll)tot [2 small L's] could be; Is it some form of type casting? tot is a global integer variable.

Could someone please enlighten me, or direct me to some resource where I can read about what exactly this (ll)variableName is.

Thanks in advance.

Community
  • 1
  • 1
Irvin H.
  • 602
  • 1
  • 10
  • 17
  • 6
    it's not `11`, it's `ll`. – Marcin Jun 01 '13 at 16:00
  • You've got `(ll)` in your code (two lowercase Ls), but `(11)` (two digits) in the question text. Which is it? –  Jun 01 '13 at 16:01
  • 5
    I don't believe that's a standard type. They may have a `typedef` line further up which defines `ll` as a `long long` or something. But yes, that syntax is a type conversion. – Dave Jun 01 '13 at 16:03
  • Ahaa, yes @Marcin & 'hvd' you're right. It's actually (ll) in the code, two lowercase L's not '(11)' i.e eleven. Ok, so now I should rephrase my question to: "What does (ll) mean [i.e. that's 2 lowercase L's]?" – Irvin H. Jun 01 '13 at 16:13
  • Absolutely correct @Dave & 'bartimar' ... there was a `typedef` somewhere at the top. Many thanks! – Irvin H. Jun 01 '13 at 16:21
  • And this bit of confusion shows why `ll` might not be a great name to use. – Michael Burr Jun 01 '13 at 18:13

1 Answers1

3

As mentioned before, it's not probably 11 (eleven), but ll (double L). You can try to search for

#define ll long long

in that code :)

It can be a custom object as well.

class ll { ... };

Or a simple typedef alias

typedef long long ll;

(thanks to user 0x499602D2 for mention this solution)

bartimar
  • 3,374
  • 3
  • 30
  • 51
  • 3
    Or it could be a simple typedef. – David G Jun 01 '13 at 16:11
  • Yes it was a `typedef` actually. Thanks :-) Still familiarizing myselft with C++ so i don't know the difference between `#define` and `typedef` – Irvin H. Jun 01 '13 at 16:23
  • 1
    #define is only a preprocessor macro... when compiling the code, all ll's are substituted with long long, then the code is compiled. Typedef is a structure very similar to class (only default private/public switched), so I consider "simple typedef" as "custom object" (hm, more like custom class or data type) - I hope this answer is fine for both of you. – bartimar Jun 01 '13 at 17:14
  • Excuse me, I read something about typedefs, I never used typedef without struct context, I will edit my answer, thx 0x499602D2, vote up :) – bartimar Jun 01 '13 at 17:21