Does anyone know if there is a citation for the anecdote of using self-mod code as a copy protection technique on the Apple II? I remember reading about it somewhere 20 years ago when I was 'into' the Apple II in high school (back when "20 megabytes" was considered "really in-humanly humungously big" LOL) [[User:Jimw338|Jimw338]] ([[User talk:Jimw338|talk]]) 21:35, 14 March 2013 (UTC)
== Javascript example is definitely not self-modifying code. ==
I'm a programmer, let me explain:
By assigning a new function to a variable, the variable will point to the new function, not the old function itself was modified.
I have two example, one in Javascript, one another in C/C++:
Javascript:
<syntaxhighlight lang="javascript">
var greet= function () {
alert("hello!");
}
var temp = hello;
greet = function () {
alert("What's 'greet'?");
}
greet(); // displaying "What's 'greet'?", you may think it is self-modifying, but wait!
temp(); // displaying "hello!", if it was self-modifying, why it is not "What's 'greet'?"!
</syntaxhighlight>
Now, the similar code for C++ 14: Pointer assigning, it works just like javascript above
<syntaxhighlight lang="C++">
#include <iostream>
int main() {
using namespace std;
auto greet = [] {
cout << "hello!\n";
};
auto temp = greet;
greet = [] {
cout << "What's 'greet'?\n";
};
greet();
temp();
return 0;
}
</syntaxhighlight>
It's is modifying value of a pointer which point to a function, so it's normally modifying a variable. So, what is really self-modifying? Self-modifying is modifying the program structure itself in memory (RAM); when a program is opened, it entire mechine code will be load in a memory region in RAM, a self-modifier will modify that region instead of modifying variables. <small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:Khải|Khải]] ([[User talk:Khải|talk]] • [[Special:Contributions/Khải|contribs]]) 15:47, 10 October 2015 (UTC)</span></small><!-- Template:Unsigned --> <!--Autosigned by SineBot-->
[[User:Khải|Khải]] ([[User talk:Khải|talk]]) 15:51, 10 October 2015 (UTC)Khải
|