本文介绍了c/c ++问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我如何将数据放入特定的地址,假设我想将数字8放入地址2000

预先谢谢大家

Hello
How can i put data in a specific address , let say i want to put the number 8 in address 2000

Thanking you all in advance

推荐答案

int *pInt = (int *)2000;
*pInt = 8;



问候
Espen Harlinn



Regards
Espen Harlinn


int *pInt = (int*)2000;
*pInt = 8;



当然,您应该注意地址.这回答了您的问题,但是...

在普通应用程序中,该语句是无用的,因为您几乎永远不会拥有任何常量地址常量.在非常老的系统中,或者在诸如嵌入式控制器之类的更奇特的东西中,可能会出现这种情况.



Of course you should be careful with address. This answers your question, but...

In a normal application, this statement is useless, because you almost never have any constant addresses constants. It can be the case in very old systems or with something more exotic like embedded controllers.


// Create an int of value val at address buffer with placement new
int* p = new (buffer) int(val);


对于您的问题是:


For your question it would be:

int* pad = new ((int*)0x2000) int(8);



欢呼声,
AR
添加了未参数化的代码.



cheers,
AR
added unparametered code.


这篇关于c/c ++问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 20:36