内存地址字面量 [英] memory address literal

查看:79
本文介绍了内存地址字面量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出十六进制格式的文本内存地址,如何在C中创建一个指向该内存位置的指针?

Given a literal memory address in hexadecimal format, how can I create a pointer in C that addresses this memory location?

我的平台(IBM iSeries)上的内存地址为128位. C类型long long也是128位.

Memory addresses on my platform (IBM iSeries) are 128bits. C type long long is also 128bits.

想象一下,我有一个字符串(char数组)的内存地址,它是:C622D0129B0129F0

Imagine I have a memory address to a string (char array) that is: C622D0129B0129F0

我假设使用正确的C语法可以直接寻址此内存位置:

I assume the correct C syntax to directly address this memory location:

const char* const p = (const char* const)0xC622D0129B0129F0ULL

我使用ULL后缀表示无符号的长整型文字.

I use ULL suffix indicate unsigned long long literal.

我的内核/平台/操作系统是否允许我这样做是一个不同的问题.我首先想知道我的语法是否正确.

Whether my kernel/platform/operating system will allow me to do this is a different question. I first want to know if my syntax is correct.

推荐答案

您的语法几乎是正确的.您不需要这些const之一:

Your syntax is almost correct. You don't need one of those const:

const char* const p = (const char*)0xC622D0129B0129F0ULL

紧接在p之前的const表示变量 p在初始化后不能更改.它不涉及p所指向的内容,因此您不需要在右侧使用它.

The const immediately before p indicates that the variable p cannot be changed after initialisation. It doesn't refer to anything about what p points to, so you don't need it on the right hand side.

这篇关于内存地址字面量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆