473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Why a vector<long long> can't be assigned a vector<int64_t> on a Linux 64bits compile

Here is a small C++ puzzling problem which blocks me in my current developments and I will appreciate any idea or explanation.

Consider the following C++ program :

Expand|Select|Wrap|Line Numbers
  1. #include <stdint.h>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main(int argC, char* argV[]) {
  6. vector<int64_t> v64;
  7. vector<long long> vll;
  8.  
  9. vll = v64;
  10. }
  11.  
On my Mac with gnu c++ (i686-apple-darwin10-g++-4.2.1) it compiles perfectly. On my SL 5.3 32 bits it compiles as well. *But* on a Centos 5.5 64bits with gnu c++ configured as follows :

Expand|Select|Wrap|Line Numbers
  1. aramis2 caillat:/tmp 510 > g++ -v
  2. Utilisation des specs internes.
  3. Target: x86_64-redhat-linux
  4. Configuré avec: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux
  5. Modèle de thread: posix
  6. version gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
  7.  
it fails to compile and gives the following error message :

Expand|Select|Wrap|Line Numbers
  1. aramis2 caillat:/tmp 511 > g++ t64.cpp 
  2. t64.cpp: In function ‘int main(int, char**)’:
  3. t64.cpp:12: erreur: no match for ‘operator=’ in ‘vll = v64’
  4. /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/vector.tcc:133: note: candidats sont: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int, _Alloc = std::allocator<long long int>]
  5. aramis2 caillat:/tmp 512 > 
  6.  
i.e. the 'long long' are not considered as equiv to 'int64_t' when they are the base type of a vector... Do you have an idea about the reason of this behaviour (shame on me if it's obvious) ?

What's even more surprising is that the compiler does not complain in front of a assignment statement where lhs is long long and rhs is int64_t but operands are scalar.
Nov 4 '10 #1
3 9234
Banfa
9,065 Expert Mod 8TB
Interesting, the problem is at the class level, that is as far as the compiler is concerned vector<int64_t> and vector<long long> are not the same type so you can't pass vector<int64_t> to a function which effectively has the prototype vector<long long>::operator=(const vector<long long>&); because they are not the same class type.

This is how templates are meant to work, instantiations with different types are not the same class.

I also not that int64_t is not current a C++ standard type but rather a C90 type. You may want to check how they are defined on both systems.

And of course since the compilers are different versions 4.2.1 and 4.1.2 they may have different behaviour and you would expect 4.2.1 to have better behaviour.

Finally being able to assign the pod types int64_t and long long to each other has no bearing on the problem because the compiler has many ways to promote and convert between pod types but the issue at point is class assignment and the compiler can only do that with the supplied assignment operators.


And even more finally I assume you are aware you can easily work round this issue in several ways, e.g. use std::copy?
Nov 4 '10 #2
Hi Banfa,

Thank you very much for your commented answer to my question. Yes the std::copy algorithm would be an elegant workaround, but unfortunately the problem I have to solve is due to a code which is generated (by SWIG not to name it :-)) not a code which is handwritten.
Nov 4 '10 #3
Banfa
9,065 Expert Mod 8TB
A-ha, well then in that case manually code a non member copy operator vector<long long>& operator=(vector<long long>&, const vector<long long>&);.

You would have to get its prototype into a header that is seen by the generated code.
Nov 4 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: VNG | last post by:
I have an ANSI C program that was compiled under Windows MSVC++ 6.0 (SP6) and under Linux gnu, and ran under P3, P4 and AMD. It runs fine on P3 and AMD under both Windows and Linux, but under P4...
1
by: Will Hurt | last post by:
Hi Ive been using midipy in my blender3d python scripts on windowsXP, now im trying to run them from ubuntu and i cant find the midipy.py module compiled for linux anywhere. Is it possible to...
5
by: Sebastien Degardin | last post by:
He everyone, Does anybody know if it's possible to load and use a library compiled on windows from a Linux application ? We have a couple of a Dll files to use in our C++ linux application. ...
13
by: ThaDoctor | last post by:
I would like to get started with programming in C, but I cant get it to work, I do not need any compiler or such. Only a basic explanation of the first program Hello World that print "Hello World"...
1
by: Nagaraj | last post by:
hi all, I have simple basic c++ program "hello world" which i cant compile on linux system. I have given extension as .C. please tell me how to compile C++ programs on Linux.
15
by: Konstantin Andreev | last post by:
I'm almost sure I've found bad bug, but for a while I can't neither confirm nor reject this. If anybody could make an independent test on it's own system, I'd appreciate it very much. The...
0
by: Rauf Sarwar | last post by:
Originally posted by aruneeshsalhotr ORACLE_HOME/bin/loadjava -user user/pwd@database -resolve <.class or jar file> Just type loadjava on command line for help. Alternately, if you have...
0
by: Manuel Vazquez Acosta | last post by:
Hi all, I'm debugging a Plone site in an AMD64 laptop. When I first tried to run Zope, I got this exception: OverflowError: signed integer is greater than maximum In the archives I...
0
by: Terry Reedy | last post by:
Manuel Vazquez Acosta wrote: In general, versions numbers for both Python and the app are helpful. Archives: Python? Zope? Plone? I hope you have/will report this to the appropriate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.