Thread: i cann`t understand this code

  1. #1
    C 1337 Meshal's Avatar
    Join Date
    Nov 2006
    Posts
    70

    i cann`t understand this code

    Code:
    char code[] = "bytecode will go here!";
    int main(int argc, char **argv)
    {
      int (*func)();
      func = (int (*)()) code;
      (int)(*func)();
    }
    i know about pointers,global declaration,string,arrays ..

    but i cann`t understand this :

    Code:
      int (*func)();
      func = (int (*)()) code;
      (int)(*func)();
    can someone explain to me please what this mean !!!!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > int (*func)();
    func is a pointer to a function. It takes unspecified parameters, and returns an int.

    > func = (int (*)()) code;
    Make func point at the code. The red bit is the cast to make it happen silently.

    > (int)(*func)();
    Call it, though the (int) is of dubious use.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM