可靠的跨平台确定只读字符串 [英] Reliably cross-platform determining read-only string

查看:82
本文介绍了可靠的跨平台确定只读字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想知道,是否有可能通过应用程序确定字符串是否可以修改(const char *)或是否它位于

什么是常见的.rodata?


问候,

彼得

Hi,

I was wondering, is it possible to determine whether a string can be
modified (const char *) by the application or whether it''s located in
what''s commonly .rodata?

Regards,
Peter

推荐答案

da ****** @ gmail。 com 写道:

我想知道,是否有可能确定字符串是否可以修改为
(const char * )通过应用程序或它是否位于

通常.rodata?
I was wondering, is it possible to determine whether a string can be
modified (const char *) by the application or whether it''s located in
what''s commonly .rodata?



如果可能,它将是实现定义的。至于

方法的可靠性,你将不得不与编译器讨论

制造商。标准C ++中没有.rodata这样的东西。


V

-

请删除资金''A'在通过电子邮件回复时

我没有回复最热门的回复,请不要问

If it is possible, it would be implementation-defined. As for the
reliability of the method, you would have to talk to the compiler
manufacturers. There is no such thing as ''.rodata'' in standard C++.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


6月27日,12:41,dasca ... @ gmail.com < dasca ... @ gmail.comwrote:
On 27 Jun, 12:41, "dasca...@gmail.com" <dasca...@gmail.comwrote:




我想知道,是否有可能确定是否可以通过应用程序对字符串进行
修改(const char *),或者它是否位于

通常是什么.rodata?


问候,

Peter
Hi,

I was wondering, is it possible to determine whether a string can be
modified (const char *) by the application or whether it''s located in
what''s commonly .rodata?

Regards,
Peter



const char *声明指向const角色对象的指针。

它无法修改。它在所有平台上都是一样的,并且所有编译器都是b $ b。你不能确定,使用C ++,

对象是静态还是动态存储。


用于编译时类型扣除你可以使用

类型特征,例如boost :: is_const。


小心你。


boost :: is_const< const char *> ; :: value为false,因为

指针不是const,只是它指向的对象


boost :: is_const< boost :: remove_pointer< const char *> :: type> :: value

是真的。


问候


DS

const char * declares a pointer to const character object.
it can not be modified. it is the same on all platforms and
all compilers. you can not determine, using C++,
whether an object is in static or dynamic storage.

for compile time type deduction you can use
type traits such as boost::is_const.

be careful thou.

boost::is_const<const char*>::value is false since the
pointer is not const, just the object it points to

boost::is_const<boost::remove_pointer<const char *>::type>::value
is true.

regards

DS


6月27日下午1点41分,dasca ... @ gmail.com < dasca ... @ gmail.comwrote:
On Jun 27, 1:41 pm, "dasca...@gmail.com" <dasca...@gmail.comwrote:

我想知道,是否有可能确定字符串是否可以修改为
(const char *)由应用程序或它是否位于

什么是常见的.rodata?
I was wondering, is it possible to determine whether a string can be
modified (const char *) by the application or whether it''s located in
what''s commonly .rodata?



如果用string表示字符串文字,则根据定义,它不能被修改,

。如果你尝试会发生什么是未定义的行为,

这意味着你无法保证这一点。 (编译器

当然可以定义这种行为。由于历史原因,一些基于Unix的

编译器确实会这样做--K& RC显然是

允许修改。但即便如此,通常还有一个

选项来禁用此扩展。)


-

James Kanze(GABI Software)电子邮件:ja ********* @ gmail.com

Conseils eninformatiqueorientéeobjet/

Beratung in objektorientierter Datenverarbeitung

9个地方Sémard,78210 St.-Cyr-l''coco,法国,+ 33(0)1 30 23 00 34

If by "string", you mean "string literal", it can''t be modified,
by definition. What happens if you try is undefined behavior,
which means you have no guarantees what so ever. (A compiler
could define this behavior, of course. Some Unix based
compilers actually do, for historical reasons---K&R C explicitly
allowed modification. But even then, there is generally an
option to disable this extension.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l''école, France, +33 (0)1 30 23 00 34


这篇关于可靠的跨平台确定只读字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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