Longest possible variable declaration?

Can any one beat const static volatile unsigned long long int x = 0; No long variable names.
Last edited on
you may add `const' add infinitum
const int * const * const * const * const
ah yeah of course
Another alternative:
1
2
3
4
5
6
template <typename T>
struct A{
    T a;
};

A<A<A<A</*...*/int/*...*/>>>> x;
This isn't a very well-specified question. You really need some more constraints.

For example, using a struct allows you to embed arbitrary code in your declaration
struct { int f() { for (int i = 0; i < 10; ++i) { blah blah } return 1; } } x;
Last edited on
OK:

1. Its decltype has to fail std::is_pointer and pass std::is_pod.
2. Definition/implementation of the data struct doesn't count -> no inline structs.
3. No whitespace, typedefs or anything cheesy. Definition only -> initialization doesn't count.
4. No decltype
Last edited on
In the spirit of things, here's something longer: (C++17)
[[deprecated("long string here")]] [[maybe_unused]] [[namespace_with::lots_of_other_really_important_attributes]] thread_local extern constexpr const volatile unsigned long long int x;
Ah yea, thread_local is defo legit. Not sure if extern counts as a declaration. So I guess

alignas(0) thread_local static constexpr const volatile unsigned long long int x = 0;

is in the lead. Althougth a const constexpr that is thread_local and volatile is a bit odd. I guess it's the ultimate way of saying "this value should never change, but if by some magic it does, keep it to 1 thread. Also despite the fact it never changes, don't cache it in a register".
Last edited on
According to the standard it (extern) seems to be.
http://eel.is/c++draft/dcl.stc

EDIT:
Just noticed your edit. No love for attributes? Two of those are even in the standard!
http://eel.is/c++draft/dcl.attr.deprecated http://eel.is/c++draft/dcl.attr.unused
Last edited on
I guess that's legit. Although mostly looking for keywords. Things that come up blue when put between [code] tags. I think they should add [[maybe_insane]] for cases like these.
Last edited on
1
2
3
4
5
6
7
8
unsigned long long int *********************************************************************************************** 
  ***********************************************************************************************
  ***********************************************************************************************
  ***********************************************************************************************
  ***********************************************************************************************
  ***********************************************************************************************
  ***********************************************************************************************
  /*4ever*/ megaPtr;
Topic archived. No new replies allowed.