"Fossies" - the Fresh Open Source Software Archive

Member "ncc-2.8/doc/fptr.c" (9 Jan 2003, 1169 Bytes) of package /linux/privat/old/ncc-2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 //
    2 //  "analyse *this"
    3 // This is a sample dummy program which demonstrates how can
    4 // ncc study pointers to functions to report a nicely connected
    5 // call graph.
    6 //
    7 typedef int (*initcall_t)(void);
    8 
    9 int init_ext2_fs (void)
   10 {}
   11 
   12 static initcall_t __init_module = init_ext2_fs;
   13 
   14 struct fs_callbacks {
   15     int (*open_file)();
   16     int (*close_file)();
   17     int (*read_bytes)();
   18     int (*write_bytes)();
   19     struct fs_callbacks *next;
   20 } FileSystems [10];
   21 
   22 int open_ext2 () {}
   23 int close_ext2 () {}
   24 int read_ext2 () {}
   25 int write_ext2 () {}
   26 int open_ffs () {}
   27 int close_ffs () {}
   28 int read_ffs () {}
   29 int write_ffs () {}
   30 
   31 struct fs_callbacks FS = {
   32     close_file: close_ext2,
   33     open_file: open_ext2,
   34     read_bytes: read_ext2,
   35     write_bytes: write_ext2
   36 };
   37 
   38 struct redirector {
   39     int (*foo)();
   40 } R = { FS.read_bytes };
   41 
   42 int main ()
   43 {
   44     struct fs_callbacks *f = &FileSystems [0];
   45     f->open_file = open_ffs;
   46     f->close_file = close_ffs;
   47     f->read_bytes = read_ffs;
   48     f->write_bytes = write_ffs;
   49     application ();
   50 }
   51 
   52 void application ()
   53 {
   54     void *p;
   55 
   56     FileSystems [2].open_file ();
   57     FileSystems [3].next->read_bytes ();    
   58     (FileSystems [2].next)->write_bytes ();
   59     ((struct fs_callbacks*)p)->next->close_file ();
   60 }