Page 1 of 1

Writing to literals shouldn't be allowed

Posted: Sat Apr 01, 2017 9:04 am
by Josh

Code: Select all

PokeS (@"aaa", "bbb")
Debug "aaa"

Re: Writing to literals shouldn't be allowed

Posted: Sun Apr 02, 2017 12:25 am
by netmaestro
What's the harm?

Re: Writing to literals shouldn't be allowed

Posted: Sun Apr 02, 2017 4:35 am
by Josh
netmaestro wrote:What's the harm?
Run the code and you will see.


P.S.: My test with:
Windows XP
Pb 560
x86

Re: Writing to literals shouldn't be allowed

Posted: Sun Apr 02, 2017 4:39 am
by juror
Makes sense to me.

Code: Select all

debug "aaa"
debug @"aaa"
PokeS (@"aaa", "bbb")
debug "aaa"

Re: Writing to literals shouldn't be allowed

Posted: Sun Apr 02, 2017 5:39 am
by Josh
juror wrote:Makes sense to me.
It's a literal and not a variable.

I don't believe that you will be happy. if writing 10'000 lines later If x$ = "aaa" and your code will get the wrong result. Purifier does not report any problems too, for this case. By the way, changes with this code also go beyond procedural and module boundaries.

Re: Writing to literals shouldn't be allowed

Posted: Sun Apr 02, 2017 5:49 am
by netmaestro
Fair enough, it doesn't look like it should be allowed for sure.

Re: Writing to literals shouldn't be allowed

Posted: Sun Apr 02, 2017 10:14 am
by freak
If you overwrite data at the wrong place in memory, you can break much more in your program than just the contents of a string. The compiler/debugger cannot protect you from that either.

I don't see why this should be any different.