i cann`t understand this code

This is a discussion on i cann`t understand this code within the C Programming forums, part of the General Programming Boards category; Code: char code[] = "bytecode will go here!"; int main(int argc, char **argv) { int (*func)(); func = (int (*)()) ...

  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
    32,854
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 08:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11: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, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21