g++


C++: Get size of enum 1

We used the following application in C++ to test the size of an enum:

#include <iostream>
using namespace std;

enum SINGLE {
        S_ZERO = 0x0,
        S_FULL = 0xFFFFFFFF
};

enum DOUBLE {
        D_ZERO = 0x0,
        D_FULL = 0xFFFFFFFFFFFFFFFF
};

int main() {
        cout << "Single Zero: Size '" << sizeof(S_ZERO) << "' Value '" << S_ZERO << "'" << endl;
        cout << "Double Zero: Size '" << sizeof(D_ZERO) << "' Value '" << D_ZERO << "'" << endl;

        cout << "Single Full: Size '" << sizeof(S_FULL) << "' Value '" << S_FULL << "'" << endl;
        cout << "Double Full: Size '" << sizeof(D_FULL) << "' Value '" << D_FULL << "'" << endl;
        return 0;
}

The output we got is the following:

Single Zero: Size '4' Value '0'
Double Zero: Size '8' Value '0'
Single Full: Size '4' Value '4294967295'
Double Full: Size '8' Value '18446744073709551615'

From the result it is pretty easy to understand that the size of an enum will grow to 64bit when any of its values is greater than 32bit.

For our test we used g++ (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) on a 64bit Fedora 23.


Ubuntu: How to compile PrecoSAT v.570 under ubuntu 11.10

By downloading PrecoSAT from http://fmv.jku.at/precosat/ and trying to install it on Ubuntu 11.10 32-bit (Oneiric Ocelot) by:

    • Decompressing the files
    • and calling ./configure && make

I got the following error at make:

g++ -O3 -m32 -static -Wall -Wextra -DNDEBUG -DNLOGPRECO -DNSTATSPRECO  -c precomain.cc
In file included from precomain.cc:23:0:
precosat.hh:164:31: error: ‘ptrdiff_t’ has not been declared
precosat.hh:270:13: error: ‘ptrdiff_t’ has not been declared
make: *** [precomain.o] Error 1

which can be resolved by adding

#include <cstddef>

at the includes in the file precosat.hh