Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
44 Views

vector size bug

When I am running this program, it will return wrong results, which are shown in the comments.

 

#include <iostream>
#include <vector>

int main()
{
  size_t n = 1000000000;
  std::vector<double> V(n);
  std::cout << V.size() << std::endl;
  // output: 1000000000

  std::cout << V.size() << std::endl;
  // output: 18446744073635809792

  std::cout << V.capacity() << std::endl;
  // output: 1000000000

  return 0;
}
 

icc for Mac

Version 19.0.1.144 Build 20181018

0 Kudos
7 Replies
Highlighted
Moderator
44 Views

these are results from my executions:

vahoang@orcsle147:/tmp$ icpc t.cpp
vahoang@orcsle147:/tmp$ ./a.out
1000000000
1000000000
1000000000

$ cat t.cpp
#include <iostream>
#include <vector>

int main()
{
  size_t n = 1000000000;
  std::vector<double> V(n);
  std::cout << V.size() << std::endl;
  // output: 1000000000
   std::cout << V.size() << std::endl;
  // output: 18446744073635809792


    std::cout << V.capacity() << std::endl;
  // output: 1000000000
  return 0;
}

vahoang@orcsle147:/tmp$ icc -V
Version 19.0.1.144 Build 20181018
 

0 Kudos
Highlighted
Beginner
44 Views

But my results are still wrong:

iMac:Documents x$ icpc test.cpp

iMac:Documents x$ ./a.out

1000000000

18446744073635809792

1000000000

iMac:Documents x$ icc -V

Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.0.1.144 Build 20181018

Copyright (C) 1985-2018 Intel Corporation.  All rights reserved.

0 Kudos
Highlighted
Beginner
44 Views

The program will show the right results only with "icpc -O1 test.cpp" instruction. If I use '-O2' or the higher optimization option, the results will be wrong.

0 Kudos
Highlighted
Beginner
44 Views

Could you tell me what are the specifications of your computer and your default optimization option?

Viet Hoang (Intel) wrote:

these are results from my executions:

vahoang@orcsle147:/tmp$ icpc t.cpp
vahoang@orcsle147:/tmp$ ./a.out
1000000000
1000000000
1000000000

$ cat t.cpp
#include <iostream>
#include <vector>

int main()
{
  size_t n = 1000000000;
  std::vector<double> V(n);
  std::cout << V.size() << std::endl;
  // output: 1000000000
   std::cout << V.size() << std::endl;
  // output: 18446744073635809792

    std::cout << V.capacity() << std::endl;
  // output: 1000000000
  return 0;
}

vahoang@orcsle147:/tmp$ icc -V
Version 19.0.1.144 Build 20181018
 

0 Kudos
Highlighted
Moderator
44 Views

I accidentally compiled at -O1; I am now seeing at -O2. I'll report this bug to our Developer.

Thanks,

Viet

 

0 Kudos
Highlighted
Moderator
44 Views

I have submitted this bug: CMPLRIL0-30860

Thanks,

Viet

0 Kudos
Highlighted
Beginner
44 Views

OK

Viet Hoang (Intel) wrote:

I have submitted this bug: CMPLRIL0-30860

Thanks,

Viet

0 Kudos