In the following code, foo, bar and baz are used as function pointers in funclist initialization.

#include <stdio.h>
typedef int (Func)();
int foo(void) { printf("foo"); };
int bar(void) { printf("bar"); };
int baz(void) { printf("baz"); };
Func *funclist [] = { foo, bar, baz };
int main(void) {
  printf("baz");
  
  baz();
  (funclist[2])();
  return 1;
}

This simple semantic patch will correctly update the call to baz in main but not in funclist initilization. The call (funclist[2])() will thus become incorrect.

@@
@@

- baz()
+ buh()

A even simplier semantic patch that will perform the right transformation is as follows.

@@

- baz
+ buh
 
ce_func_ptr.txt · Last modified: 2009/10/29 16:55 by npalix
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki