My advice on implementing stuff in C:
My advice on implementing stuff in C:
Posted Oct 19, 2010 14:46 UTC (Tue) by HelloWorld (guest, #56129)In reply to: My advice on implementing stuff in C: by nix
Parent article: Russell: On C Library Implementation
It does have to do with the name lookup rules in very non-obvious ways. I quote from "Design and Evolution of C++", page 141/142:
typedef int P(); typedef int Q(); class X { static P(Q); // define Q to be a P. // equivalent to ''static int Q()'' // the parentheses around Q are redundant // Q is no longer a type in this scope static Q(P); // define Q to be a function taking an argument of type P // and returning an int. // equivalent to ''static int Q(int()); };Declaring two functions with the same name in the same scope is fine as long as their argument types differ sufficiently. Reverse the order of member declarations, and we define twi functions called P instead. Remove the typedef for either P or Q from the context, and we get yet other meanings.
This example ought to convince anybody that standards work is dangerous to your mental health. The rules we finally adopted makes[sic] this example undefined.
Note that this example -- like many others -- is based on the unfortunate ''implicit int'' rule inherited from C.
