Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is equivalent mmap in C++ for linux?

Tags:

c++

linux

mmap

What is equivalent mmap into C++?

I have code like below

LCDdata = mmap(NULL, iFrameBufferSize, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fb_fd, 0);

Where LCDdata is unsigned char type pointer, iFrameBufferSize is int type and fb_fd is static int type.

When I compile it by use of arm g++ tool chain it give me error as below

error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]

So how can I use any equivalent type function instead of mmap?

Which header file I should include? And how this new line's syntax will become?

like image 249
secure Avatar asked Oct 24 '25 11:10

secure


1 Answers

The C++ equivalent is auto LCDdata = static_cast<unsigned char*>(mmap(...

In C++ we prefer to define out variables only when we initialize them, and because of that we often don't need to specify the type anymore. Here, we don't need to repeat unsigned char*.

like image 91
MSalters Avatar answered Oct 26 '25 02:10

MSalters