How to force a string literal into the Flash?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to force a string literal into the Flash?

1,171 次查看
bburch
Contributor III

Hi!

I have a requirement to have and embedded copyright string in this C project.  I've tried various things with pragmas, but the string always gets optimized out.

Any wisdom on this topic?

THANKS!

-Ben Burch

BTR Controls, Inc.

标记 (1)
0 项奖励
回复
3 回复数

1,076 次查看
converse
Senior Contributor V

Simple. Just make it const

e.g.

const char string = “value” ;

0 项奖励
回复

1,076 次查看
bburch
Contributor III

I thought so too, but that did not do it.  The data segment was shown as dropped in the map file.  This was verified by dumping the binary with "xxd" and examining the text representation of the binary.

What I finally did, and which did work, was to append it to a table that was referenced in the code and which was not eliminated by the linker.  But there must be a good way to do this other than that?  Yes nothing refers to it, but there should be a good way to indicate not to optimize it.

Thanks!

0 项奖励
回复

1,076 次查看
converse
Senior Contributor V

Well, I expected it to be used!

if you want to stop the linker eliminating an unused data, use

__attribute__((used)) const string = “value”;
0 项奖励
回复