c++ std::sort intel compiler error : access violation

ぐ巨炮叔叔 提交于 2019-12-13 20:27:27

问题


Why does this simple c++ code snippet do not compile?

#include <algorithm>
#define SIZE (1000)

struct S {
   int *vect;
};

int main() {

    struct S* s = static_cast<struct S*>(malloc(sizeof(struct S)));

    s->vect = static_cast<int*>(malloc(sizeof(int) * SIZE));

    for(int i = 0; i < SIZE; i++) {
       s->vect[i] = i;
    }

    std::sort(s->vect, s->vect + SIZE);

}

The compiler returns the following error related to the std::sort call

1>C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\algorithm(3138): 
error : access violation
1>              return (pair<_RanIt, _RanIt>(_Pfirst, _Plast));
1>                      ^

I'm using visual studio enterprise 2017 version 15.5.2 and the intel compiler 64 bit version 17.0.4.210 Build 20170411.

The code is successfully compiled using the default visual studio compiler.

Can't find out what I'm doing wrong.


回答1:


I've found out that unfortunately visual studio update 15.5.x breaks Intel Compiler 2017 as can be seen in the intel forum where I asked this same question. Hope it will be useful to others too.



来源:https://stackoverflow.com/questions/47901524/c-stdsort-intel-compiler-error-access-violation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!