Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Sep 2014 00:34:01 +0930
From:      Shane Ambler <BSD@ShaneWare.Biz>
To:        FreeBSD-ports <freebsd-ports@freebsd.org>
Subject:   Need help compiling use of std::vector
Message-ID:  <5422DD61.4030808@ShaneWare.Biz>

next in thread | raw e-mail | index | archive | help
I am trying to compile the new version of a port I maintain and have
trouble related to std::vector. The code producing the error can be
boiled down to the following test case, which compiles as 64bit but
fails as 32bit.

#include <stdlib.h>
#include <vector>

int main(int argc, char *argv[])
{
    int num_layers = 3;
    std::vector<const char *> layers (num_layers, NULL);

    exit(0);
}

So that should create a vector containing 3 items initially set to NULL.

10.0 compiles ok - both 32 and 64 bit. (libc++)
8.4, 9.2 and 9.3 compiles 64bit but fails on 32bit. (libstdc++)

Using the above code
clang++ -m32 test.cpp
fails with

/usr/include/c++/4.2/bits/stl_algobase.h:641:15: error: assigning to
'const char *' from incompatible type 'const int'

I often get the following with the test case - not the real code.
error: 'operator new' takes type size_t ('unsigned int') as first parameter

I have tried changing num_layers to unsigned int, size_t, std::size_t

How do I fix this to work on 32 and 64 bit?

The original code is located on line 758 at
https://github.com/imageworks/OpenShadingLanguage/blob/master/src/testshade/testshade.cpp

-- 
FreeBSD - the place to B...Software Developing

Shane Ambler




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5422DD61.4030808>