On Mon, 9 May 2022, Alessandro Carminati wrote: > Hello,I need to build a tool that just lists the global variables for a > given c project. > It appeared to me to be a straight simple operation using coccinelle, still > the script I wrote does not return the expected values. > here the script > ``` > @g@ > type T; > global idexpression T x; > @@ > x > > @script:python@ > x << g.x; > @@ > print (x) > ``` > And this is the simple file I used to test it. > ``` > #include > #include > > static char glid[3]; > int cnt; > > int function(int a){ > return a; > } > > int main(){ > char *p; > int i,c; > p=malloc(100); > i=function(9); > c=sprintf(p, "Nice text%d\n", i); > puts(p); > free(p); > return 0; > } > ``` > my expectation was to get "glid" and "cnt" as product for the computation, > instead I just get "function". >   > Could anybody clarify why this? A "global" variable is a variable that is referenced by a function but is not declared by that function. Actually, glid and cnt are not expressions. They are only identifiers. So they are not matched by idexpression. You can do what you want using some script code. I will send you a solution in a few minutes (I actually wanted to do the same thing :). julia