Thread: Eval in C?

  1. #1
    Registered User
    Join Date
    Sep 2007

    Question Eval in C?

    Hello again!

    Is there such a thing as eval in C?

    In my C-file I have this defined

    #define doSomething (0x123456)
    #define doSomethingElse (0x100efe2)

    Then I will like to read an imput from a file an instead of writing the hexadecimal value I would like to write doSomethingElse, in that way my user will know what he7she is doing and would not need to memeorize the hexadecimal values?

    Any tips?


  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Eval is not possible with C code. Though probably what you had seen was machine code "building" on runtime. I don't think that's something for beginners though...
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well simple name=value type substitutions are relatively easy to implement with a simple look up table of sorts.

    You start with say
    int doSomethingElse = 0x100efe2;

    If you then read say
    from the file, you can use a table of names to find the corresponding symbol.
    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.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Toronto, ON
    Well I know C is evil, but I have no idea what you mean by "Eval"?

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Thinking laterally:
    You could of course create a little file like this:
    // myfile.p
    #define doSomething (0x123456)
    #define doSomethingElse (0x100efe2) 
    #include myfile
    and run that through the C-preprocessor [e.g gcc -E myfile.p]

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Apr 2006
    Quote Originally Posted by cpjust View Post
    Well I know C is evil, but I have no idea what you mean by "Eval"?
    Eval is found in Perl and other scripting languages (I think -- I only know Perl). It is used to evaluate a string as if it were code.

    Can you describe what you are trying to do?
    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.

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    > Well I know C is evil, but I have no idea what you mean by "Eval"?
    Evaluate, ie evaluate a string as C code at runtime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. eval command
    By jas_atwal in forum Linux Programming
    Replies: 1
    Last Post: 11-09-2007, 11:32 PM
  2. codes
    By IfYouSaySo in forum A Brief History of
    Replies: 34
    Last Post: 11-18-2005, 03:09 PM
  3. String Manipulation
    By Nitelite in forum C Programming
    Replies: 1
    Last Post: 10-05-2002, 04:05 PM
  4. using information from an array
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 12-07-2001, 05:30 PM
  5. Problems about this eval() function
    By hei in forum C Programming
    Replies: 1
    Last Post: 11-17-2001, 01:58 PM