Writing to literals shouldn't be allowed

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Writing to literals shouldn't be allowed

Post by Josh »

Code: Select all

PokeS (@"aaa", "bbb")
Debug "aaa"
sorry for my bad english
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Writing to literals shouldn't be allowed

Post by netmaestro »

What's the harm?
BERESHEIT
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Writing to literals shouldn't be allowed

Post 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
Last edited by Josh on Sun Apr 02, 2017 4:56 am, edited 1 time in total.
sorry for my bad english
juror
Enthusiast
Enthusiast
Posts: 228
Joined: Mon Jul 09, 2007 4:47 pm
Location: Courthouse

Re: Writing to literals shouldn't be allowed

Post by juror »

Makes sense to me.

Code: Select all

debug "aaa"
debug @"aaa"
PokeS (@"aaa", "bbb")
debug "aaa"
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Writing to literals shouldn't be allowed

Post 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.
Last edited by Josh on Sun Apr 02, 2017 5:57 am, edited 1 time in total.
sorry for my bad english
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8425
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Writing to literals shouldn't be allowed

Post by netmaestro »

Fair enough, it doesn't look like it should be allowed for sure.
BERESHEIT
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Writing to literals shouldn't be allowed

Post 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.
quidquid Latine dictum sit altum videtur
Post Reply