我们可以将值分配给给定的存储位置吗?

我们可以将值分配给给定的存储位置吗?

问题描述:

我想为存储位置(例如0X12AED567)分配一些值(例如2345).能做到吗?

I want to assign some value (say 2345) to a memory location(say 0X12AED567). Can this be done?

换句话说,我该如何实现以下功能?

In other words, how can I implement the following function?

void AssignValToPointer(uint32_t pointer, int value)
{

}

答案取决于某些因素.您的程序是否在现代操作系统中运行?

The answer depends on some factors. Is your program running within a modern operating system?

如果是,尝试访问未映射的内存区域将导致SIGSEGV.为此,您必须使用系统特定的功能来映射包含此确切地址的内存区域,然后再尝试访问它.

If yes, trying to access a memory area that is not mapped will cause a SIGSEGV. To accomplish that, you have to use a system specific function to map the region of memory that contains this exact address before trying to access it.