On Thursday 07 March 2013 17:47:02 Matthijs Kooijman wrote: > Hi Tijs, > > > In general it's good to inform/promise the compiler when the program is > > not > > going to change data (using const). However, you'll have to adjust to the > > function definition types of the other functions that you are going to use > > in your new function. > > Agreed: If you need to pass the pointer on to functions that do not have > their arguments declared as non-const, you can't use const yourself > either (which indicates that const-correctness only really works when > all of the codebase uses it consistently). > > > When compiled with the appropriate flags, when passing a > > const pointer to a function as argument, which is by definition typed non- > > const, it should produce a warning/error. > > Eh? Are you saying here that you can't declare a pointer argument as > const? I'm pretty sure you can? > > E.g, this compiles: > > void func(const char *foo) {} > > void main() { > const char *x = "foo"; > func(x); > } > > But removing the const from the definition of func makes the compiler > complain.
This is what I meant ;-) Supplying a const pointer to a function which requires a non-const pointer as argument should make the compiler complain, because the function "intents" to change the data in the memory address the pointer is referring to. > Gr. > > Matthijs Thanks, Tijs _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel