Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22228

Compiler can't find 'aligned_alloc' function

$
0
0

I'm trying to launch the example code from aligned alloc:

#include <cstdio>#include <cstdlib>int main(){    int* p1 = static_cast<int*>(std::malloc(10*sizeof *p1));    std::printf("default-aligned address:   %p\n", static_cast<void*>(p1));    std::free(p1);    int* p2 = static_cast<int*>(std::aligned_alloc(1024, 1024));    std::printf("1024-byte aligned address: %p\n", static_cast<void*>(p2));    std::free(p2);}

My compilers give me this error:

$ g++-mp-8 main.cpp -std=c++17main.cpp:10:38: error: no member named 'aligned_alloc' in namespace 'std'    int* p2 = static_cast<int*>(std::aligned_alloc(1024, 1024));

I am working with macOS High Sierra 10.13.6 and tried to compile this code with Macport's GCC 7.3.0, 8.2.0 and CLang (Apple LLVM version 10.0.0), they all produce the same error.

Edit: It doesn't work with either std:: present or not.

Edit2: I installed macOS Mojave and that did not fix the problem. I hoped it'll reinstall macOS's toolchain but it didn't. So I guess I cannot accept provided answers until I get a more specific one.


Viewing all articles
Browse latest Browse all 22228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>