Build a "long long"

How you build long longin gcc is similar to building intthroughint()

In gcc (4.6.3 20120306) (but passes MSVC, for example), the following is done:

myFunctionCall(someValue, long long());

with an error expected primary-expression before 'long'(the position of the column indicates that the first long is the location).

Simple change

myFunctionCall(someValue, (long long)int());

works fine - it build intand apply to long long, indicating that gcc doesn't like long longctor.

Summary solution

To summarize the brilliant explanation below: @birryree:

  • many compilers do not support long long()and may not meet the standards
  • construction is long longequivalent to a literal 0LL, so usemyFunctionCall(someValue, 0LL)
  • use alternatively typedef long_long_t long longthenlong_long_t()
  • , uint64_t, , 64 , , 64 , .
+5
1

, comp.lang.c++.moderated .. , . ( SO),

GCC - - GCC 4.6, GCC 4.7 Clang , primary expression expected before '(', :

long long x = long long();

, , - (long() , long long() long). (, long long) type() -construction.

MSVC , ( , ).

/

, :

  • 0LL long long() - .

    , , .

  • , long long, typedef , long long, :

    int main() {
        typedef long long MyLongLong;
        long long x = MyLongLong(); // or MyLongLong x = MyLongLong();
    }
    
  • :

    template<typename TypeT>
    struct Type { typedef TypeT T(); };
    
    // call it like this:
    long long ll = Type<long long>::T();
    
  • , int64_t ( <cstdint>), - typedef long long int64_t. , .

    int64_t - , 64-, long long , linux-x86 windows-x86. long long 64 , . , .

++ 11

++ , , , , ++ 11 ( MSVC10 , ):

  • {} :

    long long ll{}; // does the zero initialization
    
  • , Johannes " bord" ++ 11 std::common_type<T>

    #include <type_traits>
    
    int main() {
        long long ll = std::common_type<long long>::type();
    }
    

, () 0 POD?

:

, ctor - - .

, .

8.5 ISO ++/2003 ( 2011 , , ):

T :

- T - -POD ( 9), T ( , T );

- T - , ;

- , .

, long long, unsigned long, int, float .. /POD- :

int x = int();

, :

int x = 0;

, :

#include <iostream>

template<typename T>
void create_and_print() {
   T y = T();
   std::cout << y << std::endl;
}

int main() {
   create_and_print<unsigned long long>();

   typedef long long mll;
   long long y = mll();
   long long z = 0LL;

   int mi = int();
}

:

g++ -fdump-tree-original construction.cxx

:

;; Function int main() (null)
;; enabled by -tree-original

{
  typedef mll mll;
  long long int y = 0;
  long long int z = 0;
  int mi = 0;

  <<cleanup_point <<< Unknown tree: expr_stmt
  create_and_print<long long unsigned int> () >>>>>;
  <<cleanup_point   long long int y = 0;>>;
  <<cleanup_point   long long int z = 0;>>;
  <<cleanup_point   int mi = 0;>>;
}
return <retval> = 0;



;; Function void create_and_print() [with T = long long unsigned int] (null)
;; enabled by -tree-original

{
  long long unsigned int y = 0;

  <<cleanup_point   long long unsigned int y = 0;>>;
  <<cleanup_point <<< Unknown tree: expr_stmt
  (void) std::basic_ostream<char>::operator<< ((struct __ostream_type *) std::basic_ostream<char>::operator<< (&cout, y), endl) >>>>>;
}

, , , , 0, , , int mi = int(). GCC , int mi = 0.

, , typename T, T = unsigned long long, 0 -initialization.


, , /POD, 0.

+5

All Articles