Thread: Program that can write its own code in C++

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    9

    Program that can write its own code in C++

    Hello everyone, i am quite new to this forum but im not new to the idea of programming. Ive looked around on the internet for some code that can write itself or even duplicate its self, but so far i havent found anything. Does anyone have any idea about how i might go about making code that can do such a thing?

    P.S.

    i know its possible, because some AI's do it, however their code is much bigger than what im looking for because they are looking to learn, im just looking for the basic code that can write something into itself while its running, based on what i give it.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Yes, but discussing this sort of stuff runs against site guidelines. Follow this link and look at point 6.

    While there is the occasional benign application of such techniques, the majority of intended applications are not benign (trojan horses, virii, etc). That is why there is little information out there about how to do it, and why it won't be discussed here.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    Well... to be honest i had no idea that that was the case, i didnt realize that this kind of code was used for virus'. Alright... well is there a place in which i can look at the syntax's for C++ and their functions? if not, or if you guys need to delete this post.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    On this site, if you look near the top of the screen, there are links to getting started with C and C++, and all sorts of things.

    If you use google, and search for terms line "introduction C" you'll also get a wealth of information.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Are you referring to quines, which are programs that print their own source code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Salem View Post
    Are you referring to quines, which are programs that print their own source code.
    From the wording " im just looking for the basic code that can write something into itself while its running, based on what i give it.", I doubt the question was about quines. It strikes me as more self-modifying or self-replicating executables.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    grumpy has it right, quines are rather simple because you can just use cout << to express all the source code

  8. #8
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by Vacrin View Post
    grumpy has it right, quines are rather simple because you can just use cout << to express all the source code
    Have you tried writing a quine before? I wouldn't call it that simple (until you see the "trick", that is).

    Why do you want self-modifying code? What are you trying to do?
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  9. #9
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    No i havent tried writing a quine before... but if i did i would mostly use cout << "source code here\n" + "more source code" and that kind of thing. the reason i want self-modifying code is so that i can make neurons. im sorta obsessed with the brain and with AI, so i figured that i would make a program that has some of basic functions of neurons and that it would be able to add to its own code as time goes on as well make new neurons if i gave it the code to, also because neurons are vary complicated and change often i would need the self-modify code so that it can edit and change itself, and also it saves me the trouble of writing all the possible code for each and every neuron ._.

  10. #10
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    No i havent tried writing a quine before
    If you haven't tried writing one before then it's pretty stupid for you to say that it's easy.

    but if i did i would mostly use cout << "source code here\n" + "more source code" and that kind of thing.
    Good luck with that! Clearly you haven't considered the problems.

    im sorta obsessed with the brain and with AI
    Who isn't?

    so i figured that i would make a program that has some of basic functions of neurons and that it would be able to add to its own code as time goes on as well make new neurons if i gave it the code to, also because neurons are vary complicated and change often i would need the self-modify code so that it can edit and change itself, and also it saves me the trouble of writing all the possible code for each and every neuron
    Overall, your "idea" is simply not very well thought out. You certainly don't need self-modifying code. It looks like you've put as much thought into this as you have into writing a quine.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  11. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    127
    You may want to read up on how AI actually works before assuming it is code that rewrites itself. If you really want to write code that is self modifying, try an interpreted language like Python (it's a language feature).

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    in AI, a neuron is a data structure, and a particular logical arrangement of neurons exhibits a particular behavior. you could say that linking up neurons in a particular arrangement might be equivalent to writing code, but it is not necessary to have a self-modifying program to do that.

  13. #13
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    Quote Originally Posted by Elkvis View Post
    in AI, a neuron is a data structure, and a particular logical arrangement of neurons exhibits a particular behavior. you could say that linking up neurons in a particular arrangement might be equivalent to writing code, but it is not necessary to have a self-modifying program to do that.
    Im not trying to make AI out of neurons, i would however like to make neurons because it would be interesting to do. now i cant run them because it would take all of my laptops computing power just to run 1 neuron because of all the equations involved, however i would like to make a program that can generate neurons in a cluster that look identical to the brain. and no im not going to try to render all 100,000,000,000 of them and their 10,000 to 200,000 connections. i would only like to render a few of them and then make it be able to render more if i so desired. now i could potentially do this without self-modifying code but i feel that it is way over complicated to write all the code that would be able to handle as all the different neurons. because within each neuron i would like them to keep track of their connections, and process and such.

    And OogaBooga
    I was wrong about only being able to use cout to make a quine because of the infinite lines problem. However from what i under stand of quines is that it just uses strings, cout, and for loops to accomplish the printing of its own code.

    But yes i have thought out my idea of writing code for neurons. however im more used to thinking in terms of logic gates rather than programming and with logic gates i can make what i describing, but with this i dont know all the words, i dont know all the Syntax or how it all fits together.

  14. #14
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Vacrin View Post
    i cant run them because it would take all of my laptops computing power just to run 1 neuron because of all the equations involved
    where did you get that idea? a neuron is a relatively simple, and computationally inexpensive data structure. in fact, a single neuron is quite useless.

  15. #15
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    Quote Originally Posted by Elkvis View Post
    where did you get that idea? a neuron is a relatively simple, and computationally inexpensive data structure. in fact, a single neuron is quite useless.
    Henry Markram: A brain in a supercomputer | Video on TED.com

    Here is where i got it, i suggest watching it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What are you using to write your code?
    By Sjvlsdsd in forum General Discussions
    Replies: 21
    Last Post: 07-23-2011, 07:20 AM
  2. How to write basic code
    By tingting in forum C Programming
    Replies: 13
    Last Post: 07-22-2009, 04:16 PM
  3. how to write save code?
    By sept in forum C++ Programming
    Replies: 6
    Last Post: 09-18-2007, 07:25 AM
  4. How do I write more efficient code?
    By minesweeper in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 11:08 AM

Tags for this Thread