Hello,

I am new to Coccinelle. I am trying to write a simple transformation
that changes memory allocation of arrays from static to dynamic.

*Example: *

      double a[x][y];

      *should be transformed to*

      double (*a)[y] = new double[x][y]; --> *the transformed code is C++,
but the original code is completely C.*


*The following patch code (reference.cocci)*

@@ identifier a; expression E1,E2; @@

-double a[E1][E2];
+double (*a)[E2] = new double[E1][E2];

*on running:* spatch -sp_file reference.cocci test.c -o test_new.c >
/dev/null

*gives:*

init_defs_builtins: /opt/tools/coccinelle//share/coccinelle/standard.h
Fatal error: exception Failure("plus: parse error:
= File "reference.cocci", line 4, column 12, charpos = 70
around = '[', whole content = +double (*a)[E2] = new double[E1][E2];
")

I have tried looking through many examples, but could not still get this to
work.
Could someone point me in the right direction ?

Thanks
Ajay
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to