Okay steve Actually I chose this API randomly from bugzilla, i don't have any plans as of now. I am developing it, as per your requirement. Out of curiosity, I started implementing this API. Actually I am a novice in development, i know somewhat like how to write code logically and make it work, but i haven't followed any standard till now. I am learning some new things from your reviews. Thanks, sameer. On Sat, 6 Mar, 2021, 9:08 am Steven Rostedt, <rostedt@xxxxxxxxxxx> wrote: > > On Sat, 6 Mar 2021 07:25:18 +0530 > Sameeruddin Shaik <sameeruddin.shaik8@xxxxxxxxx> wrote: > > > hi steve, > > > > i have one doubt. > > >Note, @filters should be of type: const char * const * filters, as not > > >only is filters pointing to constant strings, the array itself will not be > > >modified. > > > > what If the user wants to capture the filters at run time like below ? > > let's say > > > > filters = malloc(sizeof(char *)); > > if (!filters) > > return 1; > > printf("please enter the input filters count\n"); > > scanf("%d", &fil_count); > > while(i < fil_count) { > > scanf("%s", buf); > > slen = strlen(buf); > > if (!slen) > > return 1; > > filters[i] = calloc(1, slen); > > strncpy(filters[i++], buf, slen); > > } > > at that time, this declaration will be problematic right?, because we > > are trying to modify > > No it wont. You can assign const pointers to dynamic pointers, but not > the other way around. It's a way to show that the function you are > calling wont do anything with the array you pass to it. > > > the read-only memory. Are we expecting the user to supply filters at > > compile time like below? > > const char * const *filters = {"kvm_pmu_reset", "kvm_pmu_init", > > "dir_item_err", NULL}; > > No, as explained above. > > > > > Tzvetomir & steve, > > >Since a triple pointer is difficult to manage in the code, you could have: > > > > > > const char **e = NULL; > > > > > > > > > if (errs) { > > > e = realloc(sizeof(*e), j + 1); > > > e[j++] = filters[i]; > > > } > > > > > >Then at the end: > > > > > > if (errs) > > > *errs = e; > > i have a concern here > > when a double pointer is doing our work here without any overhead, why > > we want to make it a triple pointer? > > What overhead? A string is a pointer, an array of strings is a double > pointer, and passing in the address to an array of strings so you can > modify that array is a triple pointer, and that's exactly what you need > for errs. > > This is basic C coding, nothing special here. > > I'm curious to why you picked this particular API to implement. Is > there something you are planning on using this for? > > -- Steve