知道如果使用const修饰词 [英] Know if const qualifier is used

查看:158
本文介绍了知道如果使用const修饰词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何C的方式找到一个变量有const修饰符?或者如果它是存储在.RODATA节?

Is there any way in C to find if a variable has the const qualifier? Or if it's stored in the .rodata section?

例如,如果我有这样的功能:

For example, if I have this function:

void foo(char* myString) {...}

不同应采取行动在这两个不同的函数调用:

different actions should be taken in these two different function calls:

char str[] = "abc";
foo(str);

foo("def");

在第一种情况下,我可以修改字符串,在第二个无

In the first case I can modify the string, in the second one no.

推荐答案

不是标准C,即不可移植性。

Not in standard C, i.e. not portably.

的myString 只是一个的char * ,所有其他信息都将丢失。不管你送入功能将自动转换为的char *

myString is just a char* in foo, all other information is lost. Whatever you feed into the function is automatically converted to char*.

和C不知道 .RODATA

根据您的平台上,你可以检查的myString 地址(如果你知道你的地址范围)。

Depending on your platform you could check the address in myString (if you know your address ranges).

这篇关于知道如果使用const修饰词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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