Thread: Question: Can a function be nameless?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Omega Metroid View Post
    I also thought of another use for it: debugging. You know how some IDEs allow you to change the value in variables on the fly? Well, if they allowed you to input new code and store its address in a function pointer, you could quickly try new functions during the testing phase without having to stop interpretation and rewrite the program, speeding up the process.
    Visual Studio already supports edit and continue.
    Unless the change you do is extreme, you can still continue with debugging after applying changes without restarting.
    And yes, you really should trust Wikipedia.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Wikipedia is great. But not to trust 100%.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    would it be possible to make an interpreter that can change C++ code into machine code dynamically, so you can use it as something of a more secure password? (After all, if you were to make a program where the log-in function had to be manually inputted for a person to log in, it'd be pretty hard for someone to crack that 'password', I'd imagine.
    No, it wouldn't be. It would be about as hard as tracking down and extracting an obfuscated password hash. Probably easier.

    And that's completely ignoring the deeper aspects of "a few functions to make sure the code is not malicious". Heh! Now there's an ambitious project.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by C_ntua View Post
    Wikipedia is great. But not to trust 100%.
    I trust it 99%.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Sep 2009
    Posts
    63
    Another thing you can do with C++0x lambdas is have local functions within your function. You could do something like this:

    Code:
    #include <iostream>
    #include <vector>
    #include <functional>
    using namespace std;
    
    int main()
    {
    	auto hello = [] { cout << "Hello "; };
    	auto world = [] { cout << "World\n"; };
    	vector<function<void()> > test;
    	test.push_back(hello);
    	test.push_back(world);
    	for (int i = 0; i < 2; i++)
    	{
    		test[i]();
    	} 
    
    	return 0;
    }
    And now you have a vector of lambda functions contained within a single function. Perhaps that might be helpful for a script parser or something along those lines, but I haven't needed to put that into action yet.

  6. #21
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by Omega Metroid View Post
    First, I have to clarify: I probably could have worded it better, but I was talking about assigning a block of C++ code to a function pointer to dynamically make a function that didn't actually have a name. I haven't found much info on lambda functions (but then again, I admittedly haven't checked the VC++ log, and I don't exactly trust Wikipedia), though, so I had to ask. And in regards to brewbuck's post, does it have to be machine code, or would it be possible to make an interpreter that can change C++ code into machine code dynamically, so you can use it as something of a more secure password? (After all, if you were to make a program where the log-in function had to be manually inputted for a person to log in, it'd be pretty hard for someone to crack that 'password', I'd imagine. All you'd need to do is make a few functions that check whether the inputted line is code, whether it's malicious, and whether it's in the right format (specifically, if it's in the form
    Code:
    pointer = {code};
    (or would that be
    Code:
    pointer = &{code};
    ?), and then run it when you're sure. For added security, you could design the program so that the actual variable(s) needed to store log-in information changed each day, such as by using a class to use the information, and making a new instance of the class each day (you could either design the program to email you with the new instance's name or use a set name for each day, such as login_Mon, login_Tues, etc.).)
    For runtime user generated code you need a scripting language. There is no native "C++ scripting langaue", but any and perhalps all scripting languages have a C or C++ interpreter. You could probably have a Lua script, and it would be safe and easy for users to write.

    It would however be less secure than a password hash for anyone reading the files generated by your program, simply because a script needs to be revertable to the original characters, whereas a password hash would not.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CreateThread() function question
    By chiefmonkey in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2009, 07:52 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM