On Sat, 6 Mar 2021 07:25:18 +0530 Sameeruddin Shaik <sameeruddin.shaik8@xxxxxxxxx> wrote: > 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 > 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}; OK, my apologies, I see the issue that you are having, and you are correct. Because newer compiles will warn if you pass "char **" to a "const char * const *" parameter. Because it assumes that the two types are different, even when they shouldn't be. I'm not sure why the compiler wont let you pass in a char ** to a const char * const *, but it does indeed make them different. Even though there's ways to always pass strings via this logic, (you can create a "const char **" array and assign it to the dynamic one, and pass that in just fine). I looked at other prototypes, and see that the common method is. const char ** A couple do the "const char * const *" but they look to be special cases. So yes, let's go with "const char **" as we want to show that the strings will not be modified, and have "const char ***" for errs. Thanks! -- Steve